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. Delay produce in qt C++ for qt 4.8.7

Delay produce in qt C++ for qt 4.8.7

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 5 Posters 2.1k Views
  • 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.
  • MijazM Offline
    MijazM Offline
    Mijaz
    wrote on last edited by aha_1980
    #1

    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.

    jsulmJ aha_1980A 2 Replies Last reply
    0
    • MijazM Mijaz

      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.

      jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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

      JKSHJ 1 Reply Last reply
      1
      • jsulmJ jsulm

        @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?

        JKSHJ Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote on last edited by JKSH
        #3

        @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

        jsulmJ 1 Reply Last reply
        1
        • JKSHJ 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.

          jsulmJ Online
          jsulmJ Online
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

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

          1 Reply Last reply
          0
          • MijazM Mijaz

            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.

            aha_1980A Offline
            aha_1980A Offline
            aha_1980
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @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.

            MijazM 1 Reply Last reply
            1
            • aha_1980A aha_1980

              @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

              MijazM Offline
              MijazM Offline
              Mijaz
              wrote on last edited by
              #6

              @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.

              jsulmJ 1 Reply Last reply
              0
              • MijazM Mijaz

                @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.

                jsulmJ Online
                jsulmJ Online
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @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
                5
                • Pradeep P NP Offline
                  Pradeep P NP Offline
                  Pradeep P N
                  wrote on last edited by Pradeep P N
                  #8

                  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
                  1

                  • Login

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