Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Delayed function call?
Forum Updated to NodeBB v4.3 + New Features

Delayed function call?

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 4 Posters 1.7k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dan203
    wrote on last edited by
    #1

    I have a function I want to run after a dialog is displayed. I tried calling it from the showEvent handler but that's still fired before the dialog is actually displayed. Is there a way to do an async call that is delayed by a second? Or some way to fire the function after the dialog is actually displayed?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      How/when are you showing that dialog ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Dan203
        wrote on last edited by
        #3

        @SGaist said in Delayed function call?:

        Hi,

        How/when are you showing that dialog ?

        I'm calling dlg.exec() from another dialog

        1 Reply Last reply
        0
        • JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by
          #4

          add a one time timer(1s) in the showEvent to trigger it.

          D 1 Reply Last reply
          0
          • JoeCFDJ JoeCFD

            add a one time timer(1s) in the showEvent to trigger it.

            D Offline
            D Offline
            Dan203
            wrote on last edited by
            #5

            @JoeCFD How do I do that? I'm new to Qt

            eyllanescE JoeCFDJ 2 Replies Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Then you can call your method after your exec call.

              Isn't that what you are doing ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              D 1 Reply Last reply
              0
              • D Dan203

                @JoeCFD How do I do that? I'm new to Qt

                eyllanescE Offline
                eyllanescE Offline
                eyllanesc
                wrote on last edited by
                #7

                @Dan203 use QTimer:

                QTimer::singleShot(1000, [](){ qDebug() << "test"; });
                dlg.exec();

                If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

                1 Reply Last reply
                0
                • SGaistS SGaist

                  Then you can call your method after your exec call.

                  Isn't that what you are doing ?

                  D Offline
                  D Offline
                  Dan203
                  wrote on last edited by
                  #8

                  @SGaist said in Delayed function call?:

                  Then you can call your method after your exec call.

                  Isn't that what you are doing ?

                  No it's calling a function inside the dialog. Basically simulating clicking one of the buttons automatically.

                  I'm porting this from MFC. In MFC I use PostMessage to send a fake click to the button and it works as expected. Just trying to recreate it in Qt.

                  1 Reply Last reply
                  0
                  • D Dan203

                    @JoeCFD How do I do that? I'm new to Qt

                    JoeCFDJ Offline
                    JoeCFDJ Offline
                    JoeCFD
                    wrote on last edited by JoeCFD
                    #9

                    @Dan203 in showEvent
                    QTimer::singleShot(1000, this, &yourfunc ); if yourfunc is in the dialog.

                    D 1 Reply Last reply
                    1
                    • JoeCFDJ JoeCFD

                      @Dan203 in showEvent
                      QTimer::singleShot(1000, this, &yourfunc ); if yourfunc is in the dialog.

                      D Offline
                      D Offline
                      Dan203
                      wrote on last edited by
                      #10

                      @JoeCFD said in Delayed function call?:

                      QTimer::singleShot(1000, this, &yourfunc );

                      That's exactly what I needed! Thanks

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved