Не решенные How to Make a Command Prompt Using Signals and Slots?
Hi all, I am very new to Qt development. I’ve started working on an application and I would like one Widget within my application to function similar to a command prompt (but for custom commands in my application only, not an actual command prompt). Using a QLineEdit and a QPlainTextEdit I made something that approximates a command prompt. The user can type something in to the LineEdit, and when he hits enter I can parse the value and then append something to the PlainTextEdit. For example if the user types “help” I can append a help message and everything works fine. I’m stumped on how to handle more complex cases, specifically if the command requires a signal to be emitted and a response to handled in a slot. For example if the user types “process data” I want to call the function processData() which emits a signal, and it’s output is returned in a slot. That output needs to be formatted then appended to the command prompt. How would you recommend I do this? Should I be looking into synchronous signals and slots? Thanks in advance, I appreciate it.
Eeli K @psoberoi отредактировано
@psoberoi A command prompt is often by nature synchronous. You type a command and it gives output before you can type another command. If it’s asynchronous you can type new commands before the previous ones are processed and the output may come in random order. Which one do you want? If you want synchronous, you can write normal procedural code which just calls functions and returns the answer. I don’t see how signals and slots would help there at all. I mean, if you don’t need signals and slots for some external reasons (for example there’s some event driven code also in your application which already uses those signals and slots) you don’t need it for synchronous operation. But if you do need them, it should be straightforward in most basic cases where there’s no threads and one sender per one receiver and vice versa. When you create a basic connection with “connect(sender, signal, receiver, slot)” it will be synchronous. When you use emit it calls the slot as if it were a normal function call. If you have coded the signal, slot and emit yourself you could replace it with a normal function call.
psoberoi отредактировано
Thank you for the quick reply. I agree with you that a command prompt should be synchronous to the user. My issue is some of the commands I want to support require emitting signals and receiving the response via a slot. For example I support one command which spawns a new process, and I receive it’s output via a signal. How would you recommend making a signal\slot appear synchronous to the user? I’ve been trying to follow this thread: https://forum.qt.io/topic/23550/making-asynchronous-calls-work-like-synchronous-calls/4. I’m not sure if that’s the correct way for me to proceed as I need to wait for a particular slot to be called. How would I support a command that requires multiple signals/slots to run before posting it’s final output? I realize I’m in over my head. I appreciate any advice you can offer. Thanks again.
jsulm Lifetime Qt Champion @psoberoi отредактировано
@psoberoi I would just add finished() signal to all supported commands. If the user starts such a command, then the command prompt is blocked until finished() signal is emitted. No need to wait explicitly for anything. In addition your commands can have other signals, but as long as finished() is not emitted the command is not considered to be finished.
Clinical trials for CMD368 Agent(Copy Url:886cx.com)Register to receive a big gift package! Slots / Baccarat / Sportsbook / 24-hour customer service online20241016.umr
The EU Clinical Trials Register currently displays 43762 clinical trials with a EudraCT protocol, of which 7265 are clinical trials conducted with subjects less than 18 years old. The register also displays information on 18700 older paediatric trials (in scope of Article 45 of the Paediatric Regulation (EC) No 1901/2006).
Phase 1 trials conducted solely on adults and that are not part of an agreed paediatric investigation plan (PIP) are not publicly available (see Frequently Asked Questions ).
- Trials with a EudraCT protocol (0)
- Paediatric studies in scope of Art45 of the Paediatric Regulation (0)
Query did not match any clinical trials.
Query did not match any studies.
For support, Contact us.
The status and protocol content of GB trials is no longer updated since 1 January 2024. For the UK, as of 31 January 2024, EU Law applies only to the territory of Northern Ireland (NI) to the extent foreseen in the Protocol on Ireland/NI. Legal notice
As of 31 January 2024, all EU/EEA initial clinical trial applications must be submitted through CTIS . Updated EudraCT trials information and information on PIP/Art 46 trials conducted exclusively in third countries continues to be submitted through EudraCT and published on this website.
European Medicines Agency © 1995-2024 | Domenico Scarlattilaan 6, 1083 HS Amsterdam, The Netherlands
Dengan Www CMD368 Bet yang dicari: