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. Update function with timer
Forum Update on Monday, May 27th 2025

Update function with timer

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 2 Posters 5.4k 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.
  • T Offline
    T Offline
    takoo
    wrote on 26 Feb 2016, 19:51 last edited by
    #1

    İs it healty ?
    IS IT THE PROBLEM? (cpu)

    MainWindow::MainWindow(QWidget *parent) :
       QMainWindow(parent),
       ui(new Ui::MainWindow)
    {
       ui->setupUi(this);
       timer=new QTimer(this);
       timer->setInterval(500);
       timer->start();
       connect(timer,SIGNAL(timeout()),this,SLOT(update()));
    }
    
    MainWindow::~MainWindow()
    {
       delete ui;
    }
    
    int s=0;
    
    void MainWindow::update()
    {
       if(s==1)
       {
           qDebug()<<"updated";
       }
       if(s==2)
       {
           qDebug()<<"updated-2";
       }
       if(s==3)
       {
           qDebug()<<"updated-3";
       }
    
    }
    
    void MainWindow::on_pushButton_clicked()
    {
       s++;
    }
    
    

    I just write code ------- (-_-) ----------

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 26 Feb 2016, 21:04 last edited by
      #2

      Hi,

      No not really healthy. update is already a non-virtual function of QWidget. Also that static s variable is not really clean by design (not to mention that one letter variables are only to be used in very specific cases)

      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
      • T Offline
        T Offline
        takoo
        wrote on 26 Feb 2016, 21:21 last edited by
        #3

        I created own that function (update) not QWidget

        I just write code ------- (-_-) ----------

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 26 Feb 2016, 21:33 last edited by
          #4

          QMainWindow is a QWidget based class thus it inherits the update function from QWidget.

          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
          • T Offline
            T Offline
            takoo
            wrote on 26 Feb 2016, 21:59 last edited by
            #5

            no no . I am making console app

            I just write code ------- (-_-) ----------

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 26 Feb 2016, 22:17 last edited by
              #6

              Your code snippet shows a QMainWindow based class using a designer based UI with a slot connected to a QPushButton named pushButton.

              That doesn't look like a console application code.

              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
              • T Offline
                T Offline
                takoo
                wrote on 27 Feb 2016, 13:29 last edited by
                #7

                @SGaist but this app for console

                I just write code ------- (-_-) ----------

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 27 Feb 2016, 21:22 last edited by
                  #8

                  Then why are you using GUI classes ?

                  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
                  • T Offline
                    T Offline
                    takoo
                    wrote on 28 Feb 2016, 13:25 last edited by
                    #9

                    just sample above codes

                    I just write code ------- (-_-) ----------

                    1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      takoo
                      wrote on 28 Feb 2016, 13:26 last edited by
                      #10
                      #include "networkprocess.h"
                      
                      NetworkProcess::NetworkProcess(QObject *parent) : QObject(parent)
                      {
                          nam = new QNetworkAccessManager();
                          timer=new QTimer(this);
                          url2.setUrl("ftp://myserver");
                          url2.setPassword("xxx");
                          url2.setUserName("xxx");
                          url2.setPort(21);
                          req.setUrl(url2);
                      
                      
                          reply = nam->get(req);
                      
                          connect(reply, SIGNAL(readyRead()),this, SLOT(downloadReadyRead()));
                      
                          connect(reply, SIGNAL(finished()), this, SLOT(requestFinished()));
                      
                          timer->setInterval(500);
                      
                          timer->start();
                          connect(timer,SIGNAL(timeout()),this,SLOT(updatet()));
                      
                      }
                      
                      
                      
                      
                      void NetworkProcess::updatet()
                      {
                      
                             updatereply=reply;
                      
                      
                      
                      
                      }
                      
                      
                      
                      void NetworkProcess::downloadReadyRead()
                      {
                      
                          if(updatereply->error() == QNetworkReply::NoError){
                                  buf = updatereply->readAll();
                                  if(buf=="Kapat")
                                  {
                                    qDebug()<<"tako";
                                  }
                      
                      
                                  if(buf=="Ac")
                                  {
                                      qDebug()<<"vural";
                                  }
                      
                              }
                      }
                      
                      void NetworkProcess::requestFinished()
                      {
                      
                      }
                      
                      
                      

                      this is

                      I just write code ------- (-_-) ----------

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 28 Feb 2016, 20:17 last edited by
                        #11

                        That update function doesn't really make sense. The reply is automatically updated while the request is being processed.

                        Why not use the downloadProgress signal if you want information about the downloading state of your query ?

                        On a side note there's the QtFTP module that you can use to access a FTP server.

                        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
                        • T Offline
                          T Offline
                          takoo
                          wrote on 29 Feb 2016, 14:02 last edited by
                          #12

                          I used QT5.5 . There is no qtftp.

                          I just write code ------- (-_-) ----------

                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on 29 Feb 2016, 14:19 last edited by
                            #13

                            Please, take the time to do a bit of search: http://code.qt.io/cgit/qt/qtftp.git/

                            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
                            • T Offline
                              T Offline
                              takoo
                              wrote on 29 Feb 2016, 14:43 last edited by
                              #14

                              @SGaist how to I install this ?

                              I just write code ------- (-_-) ----------

                              1 Reply Last reply
                              0
                              • S Offline
                                S Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on 29 Feb 2016, 21:43 last edited by
                                #15
                                git clone https://code.qt.io/qt/qtftp.git
                                cd qtftp
                                qmake
                                make
                                make install
                                

                                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

                                1/15

                                26 Feb 2016, 19:51

                                • Login

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