remove timer single shot delay after a condition is met
-
i have a button, on click it should check availability of some dependent app, and if it's not loaded, load it, otherwise just execute the functionality of the button
now, since the app load can take time, i have added 200ms singleShot timer for button actual slot, i have two connections:
void checkLoad() { try to load another app } void onBtnClick() { if not loaded, return qtimer:: singleShot (200, this, [] { ... }); }
how can i not have to singleShot when app is loaded? i.e. only have singleShot delay if app was first time loaded, next times i don't wanna have delay
-
Don't use a singleShot timer but a QTimer object.
-
@Christian-Ehrlicher
ok, so in timeout slot, can i callstop()
?
but i want to the click actual slot to execute, just without delay. how does timer help here? -
Hi,
Rather than relying on some arbitrary delay, can't you establish a communication with that other app to know when it's up and running ?
-
@SGaist
i do know that info. but the first time the app is loaded, i need to process some initial setup sent from it. that's why the delay in button slots.so i do need the delay, but only first time button clicking and app loading
-
@user4592357 said in remove timer single shot delay after a condition is met:
i need to process some initial setup sent from it
How does it send this initial setup and how do you read it?
-
@user4592357 said in remove timer single shot delay after a condition is met:
but i want to the click actual slot to execute, just without delay. how does timer help here?
I don't understand - in your question you say you use a singleShot timer to delay something, now you say you won't delay anything. Please clarify what you really need.
-
@Christian-Ehrlicher
ok i will store the ms delay and set it to x ms initially, and after first time click (when app is already loaded), i wll set the delay to 0ms -
Or simply delete it after the first click and do you stuff directly.
-
The question is: since you already get data from that other app, why not also make it communicate that it is ready ? So you don't have that delay at all. You can then disable the button until everything is ready.
In your actual situation you will have your users able to click on a button that might do nothing or something with a delay which is not a really nice user experience. -
@Christian-Ehrlicher
delete what? -
@user4592357 said in remove timer single shot delay after a condition is met:
@Christian-Ehrlicher
delete what?The timer object? Because you told us you don't need it anymore.
-
ok, i start the child process start detached.
and it looks like the app is started and it continues to send startup configuration even after my first slot (which invokes the child process) has finished.
and that's why i have added delay in the actual (2nd) slotso how can i make sure the child process does its initialisation inside the first slot, and not after it has finished?
-
@user4592357 said in remove timer single shot delay after a condition is met:
so how can i make sure the child process does its initialisation inside the first slot, and not after it has finished
You can't. You have no control over, or knowledge of, what the child is doing in the way of initialisation or otherwise. Quite apart from, you don't even know how the OS is scheduling time between your process and another process.
i.e. only have singleShot delay if app was first time loaded, next times i don't wanna have delay
To answer just that: just keep a
bool
variable to tell you whether it's first time or not, and don't do delay if you say you don't want it after first time.