Hello,
I want to add checkLatestVersion functionality to my program. My program will connect foo.com/bar.file and get the latestVersion and compares with currentVersion. If latestVersion is greater then currentVersion that it will give a message (there is a new version, download it) and then quit.
Here is my code:
void VersionChecker::checkVersion()
{
versionHttp
= new QHttp();
connect(versionHttp,SIGNAL(requestFinished(int,bool)),this,SLOT(versionHttpData(int,bool)));
versionHttp>setHost("www.foo.com", 80);
versionHttpRequestId = versionHttp->get("/bar/latest.txt");
}
void VersionChecker::versionHttpData(int id, bool error)
{
if (id != versionHttpRequestId)
{
return;
}
if(error)
{
latestVersionString = "2.0.0.0";
return;
}
latestVersionString = versionHttp->readAll();
}
QString VersionChecker
::getLatestVersion() {
return latestVersionString;
}
void VersionChecker::checkVersion()
{
versionHttp = new QHttp();
connect(versionHttp,SIGNAL(requestFinished(int,bool)),this,SLOT(versionHttpData(int,bool)));
versionHttp>setHost("www.foo.com", 80);
versionHttpRequestId = versionHttp->get("/bar/latest.txt");
}
void VersionChecker::versionHttpData(int id, bool error)
{
if (id != versionHttpRequestId)
{
return;
}
if(error)
{
latestVersionString = "2.0.0.0";
return;
}
latestVersionString = versionHttp->readAll();
}
QString VersionChecker::getLatestVersion()
{
return latestVersionString;
}
To copy to clipboard, switch view to plain text mode
and how i use it:
VersionChecker *versionControl = new VersionChecker();
versionControl->checkVersion();
QString latestVersion
= versionControl
->getLatestVersion
();
if(latestVersion != _PROGRAM_VERSION)
{
NewVersionAvailableDialog *newVersionDialog = new NewVersionAvailableDialog();
newVersionDialog->setModal(true);
newVersionDialog->setAttribute( Qt::WA_DeleteOnClose );
newVersionDialog->show();
return a.exec();
}
MainForm w;
w.show();
a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
return a.exec();
QApplication a(argc, argv);
VersionChecker *versionControl = new VersionChecker();
versionControl->checkVersion();
QString latestVersion = versionControl->getLatestVersion();
if(latestVersion != _PROGRAM_VERSION)
{
NewVersionAvailableDialog *newVersionDialog = new NewVersionAvailableDialog();
newVersionDialog->setModal(true);
newVersionDialog->setAttribute( Qt::WA_DeleteOnClose );
newVersionDialog->show();
return a.exec();
}
MainForm w;
w.show();
a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
return a.exec();
To copy to clipboard, switch view to plain text mode
The problem is, the program runs, QHttp connects and gets the latest version but, while these are being MainWindow is shown. I dont want it to be shown. Firstly latestVersion control must be finished. If current version is the latest version, then MainWindow must shown, otherwise i want the program to quit.
How can I do that? Where's the problem?
Bookmarks