Update function with timer
-
wrote on 26 Feb 2016, 19:51 last edited by
İ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++; }
-
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)
-
wrote on 26 Feb 2016, 21:21 last edited by
I created own that function (update) not QWidget
-
QMainWindow is a QWidget based class thus it inherits the
update
function from QWidget. -
wrote on 26 Feb 2016, 21:59 last edited by
no no . I am making console app
-
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.
-
Then why are you using GUI classes ?
-
wrote on 28 Feb 2016, 13:25 last edited by
just sample above codes
-
wrote on 28 Feb 2016, 13:26 last edited by
#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
-
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.
-
wrote on 29 Feb 2016, 14:02 last edited by
I used QT5.5 . There is no qtftp.
-
Please, take the time to do a bit of search: http://code.qt.io/cgit/qt/qtftp.git/
-
git clone https://code.qt.io/qt/qtftp.git cd qtftp qmake make make install
1/15