Не решенные 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.
TENCON 2024
The Tropical Cyclone Warning Signal Number 8 was hoisted on 2 Nov 2024. The Hong Kong Government has announced that the testing deadline for undergoing compulsory testing will be extended by one day https://www.info.gov.hk/gia/general/202411/02/P2024110200571.htm . Participants who missed their PCR test on 2 Nov 2024 can do their PCR test on 3 Nov 2024.
For participants who arrived Hong Kong on or after 1 Nov 2024, their LeaveHomeSafe App should still be showing the amber code on 3 Nov 2024. They will NOT be able to join the Gala Dinner in the evening of 3 Nov 2024. TENCON 2024 will compensate each of these amber code participants by cash (HKD 800) at the TENCON registration counter (from Eddy Chiu) in HKCEC from 10:00 to 16:00 on 3 Nov 2024. Please present proof of your arrival date (e.g. air ticket) at the registration counter upon receiving the cash compensation.
To participants of the gala dinner, please be reminded to present photo of your (same day) RAT result upon entry of the diner venue.
Jessica shares vegan and vegetarian recipes that are heavy on fruits, veggies, grains, and healthy fats. Her chickpea tacos are great for Meatless Monday or Taco Tuesday, and her no-bake pumpkin chocolate cups are an awesome dessert to keep on hand. Follow her on Pinterest.
From everyone’s favourite QQKeno to over five (5) variety of online lottery games and around the clock action from Beijing, Australia, Canada, and more, BK8 has all it takes to bring the fun in lottery games to a whole new level!
View historical imagery to see changes over the years.* * earliest images from 2007 – availability varies
“Selama tiga tahun kemitraan ini berlangsung, kami akan bekerja keras untuk berpengaruh kepada masyarakat dengan membuat sejumlah program di seluruh wilayah yang melibatkan suporter Aston Villa, tidak hanya lokal tetapi juga dalam skala global,” tutur Gatt.
Dan favoritkan produk yg juragan minati agar dikemudian hari dapat memudahkan jika ingin transaksi sekaligus notifikasi/pemberitahuan jika produk sedang diskon.
:
- Apakah CMD368 Penipu
- Link Alternatif CMD368 2024
- CMD368 Live Sportsbook
- Sportbook CMD368
- Linkalternatif CMD368