Looking to call a function withour user intervention
-
Thank you for your reply.
Ah yes. I had tried that but discarded it as a QMessageBox poping up outside of, or before the main window appears just looks wrong to me. I would like the UI to settle before doing this. -
Thank you for your reply.
Ah yes. I had tried that but discarded it as a QMessageBox poping up outside of, or before the main window appears just looks wrong to me. I would like the UI to settle before doing this.@bart.hollis
If that's what you want, you could set off a one-shotQTimer
(just prior toQApplication::exec()
) to bring up your UI after a fraction of a second.EDIT: Or, maybe
QEvent::Show
inQMainWindow::event(QEvent *event)
(orQWidget::showEvent
) will be raised when your main window has been shown.There are all sorts of suggestions in https://stackoverflow.com/questions/14356121/how-to-call-function-after-window-is-shown
-
Hi,
Some something like:
- "show widgets"
- Start method while widgets are visible
?
-
Thank you for your reply.
Ah yes. I had tried that but discarded it as a QMessageBox poping up outside of, or before the main window appears just looks wrong to me. I would like the UI to settle before doing this.@bart.hollis What's making the main window appear? If you want to be able to tell the main window to either show data or prompt the user about populating it with sample data as soon as it opens, that might be a good place to put the check for the data.
-
@SGaist said in Looking to call a function withour user intervention:
Hi,
Some something like:
- "show widgets"
- Start method while widgets are visible
?
Yup! That's what I want to do, but can't seem to find something, or one of the widgets that will trigger the function. Wish I could get into the actual loop! :)
-
Use a
QTimer::singleShot
with a value of 0 for the delay, then you'll have your GUI running and the method called right after the first round of the event loop. -
Use a
QTimer::singleShot
with a value of 0 for the delay, then you'll have your GUI running and the method called right after the first round of the event loop.@SGaist said in Looking to call a function withour user intervention:
Use a
QTimer::singleShot
with a value of 0 for the delay, then you'll have your GUI running and the method called right after the first round of the event loop.Could you please give me more detail as how to implement this?
-
Same as usual except that you use 0 as timeout value and you call that as the last thing in your constructor.
-
@SGaist said in Looking to call a function withour user intervention:
Use a
QTimer::singleShot
with a value of 0 for the delay, then you'll have your GUI running and the method called right after the first round of the event loop.Could you please give me more detail as how to implement this?
@bart.hollis
I suggested you look at https://stackoverflow.com/a/38749911/489865 or which does actually give code for usingQTimer::singleShot
. -
Same as usual except that you use 0 as timeout value and you call that as the last thing in your constructor.
@SGaist said in Looking to call a function withour user intervention:
Same as usual except that you use 0 as timeout value and you call that as the last thing in your constructor.
That would be the MainWindow constructor?
Then, do I understand correctly that I use the slot mentioned to trigger my function?
From Docs: QTimer::singleShot(200, this, SLOT(updateCaption()));
-
SGaist
Your suggestion works just as I want! Now, I just need to understand WHY! :) -
Now, I need to mark this thread as solved. I know how to do that!
But I should click something that gives points to reputation. I know I saw that somewhere! (mutter, mutter, mutter) I hate when I don't know what I'm doing!Anyway, Thanks SGaist! Very Much!
-
Now, I need to mark this thread as solved. I know how to do that!
But I should click something that gives points to reputation. I know I saw that somewhere! (mutter, mutter, mutter) I hate when I don't know what I'm doing!Anyway, Thanks SGaist! Very Much!
You can upvote a post with the small up arrow right below each post. The down arrow is for downvoting (and should be used in rare cases). The number in between the both shows the current voting for a post and are therefore a sign for it's quality.
Regards
-
AHA! (Not trying to steal your handle!) Thanks!
-
AHA! (Not trying to steal your handle!) Thanks!
@bart.hollis You're welcome :)