Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    Unsolved Delay produce in qt C++ for qt 4.8.7

    General and Desktop
    5
    8
    1233
    Loading More Posts
    • 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.
    • Mijaz
      Mijaz last edited by aha_1980

      I want to produce delay in my code for 500ms. I have tried following commands.
      1). QThread::msleep(500);
      2). delay(500);
      3). sleep(500);

      command (1). produce delay but when I deploy the project to my SDR board it pops error that "QThread cannot yous in this scope" because my board running qt4.8.7 not the latest. So I used 2). and 3). but they are not working.
      Please guide me how I can produce a delay for qt4.8.7 version.

      jsulm aha_1980 2 Replies Last reply Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion @Mijaz last edited by

        @Mijaz It is already supported in Qt4: https://doc.qt.io/archives/qt-4.8/qthread.html#msleep
        When and where do you get that error?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        JKSH 1 Reply Last reply Reply Quote 1
        • JKSH
          JKSH Moderators @jsulm last edited by JKSH

          @jsulm said in Dealy produce in qt C++ for qt 4.8.7:

          It is already supported in Qt4: https://doc.qt.io/archives/qt-4.8/qthread.html#msleep

          QThread::msleep() is public in Qt 5 but protected in Qt 4. So, Qt 4, QThread::msleep() must be called by a QThread subclass.

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          jsulm 1 Reply Last reply Reply Quote 1
          • jsulm
            jsulm Lifetime Qt Champion @JKSH last edited by

            @JKSH Oh, you're right it's early morning here :-)

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 0
            • aha_1980
              aha_1980 Lifetime Qt Champion @Mijaz last edited by

              @Mijaz all the calls you mentioned are blocking. The better way is to use a QTimer and connect a slot to the timeout() signal.

              Regards

              Qt has to stay free or it will die.

              Mijaz 1 Reply Last reply Reply Quote 1
              • Mijaz
                Mijaz @aha_1980 last edited by

                @aha_1980
                I tried to use QTimer but I don't understand, how it will use for my purpose.
                Will you please help me to write a simple widget program in which when I click a pushButton1 the LineEdit start blink and when click pushButton2 LineEdit stops blink.

                jsulm 1 Reply Last reply Reply Quote 0
                • jsulm
                  jsulm Lifetime Qt Champion @Mijaz last edited by

                  @Mijaz You have it here: https://forum.qt.io/topic/65799/how-to-display-label-for-30-seconds-and-then-hide-it/30
                  There is really nothing special to it:

                  QTimer *timer = new QTimer(this);
                  connect(timer, &QTimer::timeout, this, &MainWindow::toggleLineEdit);
                  timer->start(1000);
                  
                  void MainWindow::toggleLineEdit()
                  {
                      ui->lineEdit->setChecked(!ui->lineEdit->checked());
                     ...
                  }
                  

                  Your both buttons then simply start the timer or stop it.

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply Reply Quote 5
                  • Pradeep P N
                    Pradeep P N last edited by Pradeep P N

                    Hi @Mijaz

                    You can also use QEventLoop check below methods from documentation.

                    • exec() : Enters the main event loop and waits until exit() is called. Returns the value that was passed to exit().
                    • exit() : Tells the event loop to exit with a return code.

                    Hope this may help you.
                    All the best.

                    Pradeep Nimbalkar.
                    Upvote the answer(s) that helped you to solve the issue...
                    Keep code clean.

                    1 Reply Last reply Reply Quote 1
                    • First post
                      Last post