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. QTimer Pointer Out of Scope?

QTimer Pointer Out of Scope?

Scheduled Pinned Locked Moved Solved General and Desktop
qt4qtimerqprogressdialog
4 Posts 2 Posters 1.8k 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.
  • D Offline
    D Offline
    DougyDrumz
    wrote on last edited by
    #1

    My slots seem to have a NULL pointer for myProgressTimer for the following code. I.e., When myProgressDialog exceeds the maximum value, or it is canceled, "myProgressTimer is NULL" is reported. However, the timer is still running. Any ideas?

    class MyGUI : public QMainWindow
    {
    ...
    private slots:
    ...
        void updateProgress();
        void cancelProgress();
    ...
    private:
    ...
        QProgressDialog* myProgressDialog;
        QTimer*                myProgressTimer;
    ...
    }
    
    MyGUI::MyGUI(QWidget *parent)
        : QMainWindow(parent)
    ...
    ,myProgressDialog(0)
    ,myProgressTimer(0)
    {
    ...
    void MyGUI::startSystem()
    {
    ...
        myProgressDialog = new QProcessDialog("Starting system...", "Cancel", 0, 20);
        QTimer *myProgressTimer = new QTimer(this);
        connect(myProgressDialog, SIGNAL(canceled()), this, SLOT(cancelProgress()));
        connect(myProgressTimer, SIGNAL(timeout()), this, SLOT(updateProgress()));
        myProgressTimer->start(1000);
    }
    ...
    void MyGUI::updateProgress()
    {
        static int steps = 0;
        
        myProgressDialog->setValue(steps++);
    
        if (setps > myProgressDialog->maximum())
        {
            myProgressDialog->cancel();
    
            if (myProgressTimer )
            {
                myProgressTimer->stop();
            }
            else
            {
                cout << "myProgressTimer is NULL" << endl;
            }
        }
    }
    
    void MyGUI::cancelProgress()
    {
        myProgressDialog->cancel();   
    
        if (myProgressTimer )
        {
            myProgressTimer->stop();
        }
        else
        {
            cout << "myProgressTimer is NULL" << endl;
        }        
     }
    
    

    Dougy Drumz

    kshegunovK 1 Reply Last reply
    0
    • D DougyDrumz

      My slots seem to have a NULL pointer for myProgressTimer for the following code. I.e., When myProgressDialog exceeds the maximum value, or it is canceled, "myProgressTimer is NULL" is reported. However, the timer is still running. Any ideas?

      class MyGUI : public QMainWindow
      {
      ...
      private slots:
      ...
          void updateProgress();
          void cancelProgress();
      ...
      private:
      ...
          QProgressDialog* myProgressDialog;
          QTimer*                myProgressTimer;
      ...
      }
      
      MyGUI::MyGUI(QWidget *parent)
          : QMainWindow(parent)
      ...
      ,myProgressDialog(0)
      ,myProgressTimer(0)
      {
      ...
      void MyGUI::startSystem()
      {
      ...
          myProgressDialog = new QProcessDialog("Starting system...", "Cancel", 0, 20);
          QTimer *myProgressTimer = new QTimer(this);
          connect(myProgressDialog, SIGNAL(canceled()), this, SLOT(cancelProgress()));
          connect(myProgressTimer, SIGNAL(timeout()), this, SLOT(updateProgress()));
          myProgressTimer->start(1000);
      }
      ...
      void MyGUI::updateProgress()
      {
          static int steps = 0;
          
          myProgressDialog->setValue(steps++);
      
          if (setps > myProgressDialog->maximum())
          {
              myProgressDialog->cancel();
      
              if (myProgressTimer )
              {
                  myProgressTimer->stop();
              }
              else
              {
                  cout << "myProgressTimer is NULL" << endl;
              }
          }
      }
      
      void MyGUI::cancelProgress()
      {
          myProgressDialog->cancel();   
      
          if (myProgressTimer )
          {
              myProgressTimer->stop();
          }
          else
          {
              cout << "myProgressTimer is NULL" << endl;
          }        
       }
      
      
      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      @DougyDrumz
      Hello,

      QTimer *myProgressTimer = new QTimer(this);
      

      This line is in your constructor is bogus. You're hiding the global scope and are assigning the object's address to a local pointer variable.

      Kind regards.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      2
      • D Offline
        D Offline
        DougyDrumz
        wrote on last edited by
        #3

        Duh! Good catch!

        Dougy Drumz

        kshegunovK 1 Reply Last reply
        0
        • D DougyDrumz

          Duh! Good catch!

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

          @DougyDrumz
          Easy peasy ... no one seems to want to answer my questions though. ;)
          Happy coding!

          Read and abide by the Qt Code of Conduct

          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