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. QMessageBox show() not displaying text
Forum Updated to NodeBB v4.3 + New Features

QMessageBox show() not displaying text

Scheduled Pinned Locked Moved Solved General and Desktop
25 Posts 6 Posters 13.5k Views 3 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.
  • mrjjM mrjj

    @mzimmers

    • timer.isActive() never returns true.
      Well if it takes more than 1 sec before the containing slot is called again then is it then not true that timer.isActive() is false?
      also the single shot might not even set active. maybe only start() does.
      (just speculating)
    mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by mzimmers
    #21

    @mrjj said in QMessageBox show() not displaying text:

    Well if it takes more than 1 sec before the containing slot is called again then is it then not true that timer.isActive() is false?

    If it takes more than 1 second (which it never does), the isActive should report false, and a new singleShot should be called. At least that's what I'm attempting to do.

    also the single shot might not even set active. maybe only start() does.
    (just speculating)

    Interesting...I'll replace the singleShot with a conventional timer and report back.

    kshegunovK 1 Reply Last reply
    0
    • mzimmersM mzimmers

      @mrjj said in QMessageBox show() not displaying text:

      Well if it takes more than 1 sec before the containing slot is called again then is it then not true that timer.isActive() is false?

      If it takes more than 1 second (which it never does), the isActive should report false, and a new singleShot should be called. At least that's what I'm attempting to do.

      also the single shot might not even set active. maybe only start() does.
      (just speculating)

      Interesting...I'll replace the singleShot with a conventional timer and report back.

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by kshegunov
      #22

      singleShot is a static function, it calls setSingleShot(true) and then start(). As this function doesn't really require an object it also does not modify your object in any way, effectively you're calling QTimer::singleShot.

      PS.
      Use like this:

      timer.setSingleShot(true);
      QObject::connect(&timer, &QTimer::timeout, this, &WhateverYourClassIsNamed::sendDiscoveryRequest);
      // ...
      if (devState == RESETTING)  {
          if (timer.isActive()) // only do one at a time.
              qDebug() << "\t\ttimer already queued.";
          else  {
              timer.start(1000);
              qDebug() << "\t\tqueueing timer.";
          }
      }
      

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      1
      • mzimmersM Offline
        mzimmersM Offline
        mzimmers
        wrote on last edited by
        #23

        OK, I found why the timer wasn't working for me. It turns out I defined the QTimer * variable twice: once as a member of my Worker class, and once again in the Worker constructor. General hilarity ensued.

        I'm not saying this wasn't my fault, but I'd have expected the damn compiler to at least give me a warning when I did this.

        Thanks to all for the help on the QTimer. Now that my communications sequence is intact, I can review my approach to the original problem with the QMessageBox. I'll report back when I have something.

        kshegunovK 1 Reply Last reply
        0
        • mzimmersM mzimmers

          OK, I found why the timer wasn't working for me. It turns out I defined the QTimer * variable twice: once as a member of my Worker class, and once again in the Worker constructor. General hilarity ensued.

          I'm not saying this wasn't my fault, but I'd have expected the damn compiler to at least give me a warning when I did this.

          Thanks to all for the help on the QTimer. Now that my communications sequence is intact, I can review my approach to the original problem with the QMessageBox. I'll report back when I have something.

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by kshegunov
          #24

          @mzimmers said in QMessageBox show() not displaying text:

          I'm not saying this wasn't my fault, but I'd have expected the damn compiler to at least give me a warning when I did this.

          Not a thing that warrants a warning. Shadowing is a normal feature of the language, and you can see it quite a lot in my code. Without this I'd get a ton of warnings for correct usage of a valid language construct. For example for a generic QObject subclass (a situation that happens all the time):

          class MyClass : public QObject
          {
          public:
              MyClass(QObject * parent = nullptr) //< `parent` shadows QObject::parent()
                  : QObject(parent)
              {
              }
          };
          

          Or even more elaborate:

          void QMpiCompoundRequestPrivate::requestFinished(QMpiRequest * child)
          {
              if (!subrequests.remove(child))
                  return;
          
              Q_Q(QMpiCompoundRequest);
              emit q->finished(child);
              if (subrequests.size() == 0)
                  emit q->QMpiRequest::finished();
          }
          

          See how the second signal emission is done. That's because in the derived class (QMpiCompoundRequest) there's a function that shadows the base class' (QMpiRequest) method (even though with different set of parameters). So in this case you must be explicit which function exactly you're calling.

          Read and abide by the Qt Code of Conduct

          mzimmersM 1 Reply Last reply
          2
          • kshegunovK kshegunov

            @mzimmers said in QMessageBox show() not displaying text:

            I'm not saying this wasn't my fault, but I'd have expected the damn compiler to at least give me a warning when I did this.

            Not a thing that warrants a warning. Shadowing is a normal feature of the language, and you can see it quite a lot in my code. Without this I'd get a ton of warnings for correct usage of a valid language construct. For example for a generic QObject subclass (a situation that happens all the time):

            class MyClass : public QObject
            {
            public:
                MyClass(QObject * parent = nullptr) //< `parent` shadows QObject::parent()
                    : QObject(parent)
                {
                }
            };
            

            Or even more elaborate:

            void QMpiCompoundRequestPrivate::requestFinished(QMpiRequest * child)
            {
                if (!subrequests.remove(child))
                    return;
            
                Q_Q(QMpiCompoundRequest);
                emit q->finished(child);
                if (subrequests.size() == 0)
                    emit q->QMpiRequest::finished();
            }
            

            See how the second signal emission is done. That's because in the derived class (QMpiCompoundRequest) there's a function that shadows the base class' (QMpiRequest) method (even though with different set of parameters). So in this case you must be explicit which function exactly you're calling.

            mzimmersM Offline
            mzimmersM Offline
            mzimmers
            wrote on last edited by
            #25

            @kshegunov thanks for the explanation. I had never seen shadowing before, probably because I'd done very little work with derived classes. Good stuff to know going forward.

            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