When just loaded, the app is fairly smooth, however with time passing by, the gui gets slower and slower, which is, when i click a button, it will only take effect after a few seconds(1 or 2).
I have watched the process in task-manager, the memory usage is stable(around 5m), and before i click the buttons, the cpu usage is also 0.
I am using Qt_4.8.0 with visual_studio_2010.
Is it because of the efficiency of qt lib on windows?
Some code:
/////////mainwindow.h////////////
QPushButton* reloadHostsPushButton = new QPushButton("Reload Hosts");
reloadHostsPushButton->setMaximumSize(aPushButtonMaxSize);
connect(reloadHostsPushButton, SIGNAL(clicked()),
this, SLOT(reloadHostsClicked()));
QPushButton* flushDNSPushButton = new QPushButton("Flush DNS Cache");
flushDNSPushButton->setMaximumSize(aPushButtonMaxSize);
connect(flushDNSPushButton, SIGNAL(clicked()),
this, SLOT(flushDNSClicked()));
controlPanelLayout = new QGridLayout();
controlPanelLayout->addWidget(openHostsPushButton, 0, 0);
controlPanelLayout->addWidget(reloadHostsPushButton, 0, 1);
controlPanelLayout->addWidget(flushDNSPushButton, 0, 2);
controlPanelLayout->addWidget(quitPushButton, 1, 2);
controlPanelLayout->addWidget(aboutPushButton, 1, 1);
controlPanelLayout->addWidget(optionsPushButton, 1, 0);
controlPanel = new QWidget();
controlPanel->setLayout(controlPanelLayout);
/////////server.h//////////////flushDNSClicked() calls this/////////
void Server::flushDNSCache(){
ui_LogPanel->log("Flushing DNS cache...", UI_LogPanel::aLogRed);
QProcess* tmp = new QProcess();
tmp->start("ipconfig", QStringList() << "/flushdns");
ui_LogPanel->log("DNS cache flushed!", UI_LogPanel::aLogItalic | UI_LogPanel::aLogGreen);
}
Your flushDNSCache() slot function contains a bug and some wishful thinking. Although I don’t think that it will cause the slowdown.
You are creating a QProcess object but you are never deleting it. And you are printing to the log that the DNS cache is flushed, wishing that everything went okay.
If you don’t care whether the ipconfig succeeded, you can use QProcess::startDetached as follows:
Now you don’t leave any undeleted QProcess objects hanging around.
Even better would be to use QProcess::execute:
Now you can check the exit code. Note however, that the QProcess::execute will wait until the process finishes so if you start long running process your application will freeze until the process finishes.