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:
Qt Code:
  1. void VersionChecker::checkVersion()
  2. {
  3. versionHttp = new QHttp();
  4. connect(versionHttp,SIGNAL(requestFinished(int,bool)),this,SLOT(versionHttpData(int,bool)));
  5. versionHttp>setHost("www.foo.com", 80);
  6. versionHttpRequestId = versionHttp->get("/bar/latest.txt");
  7. }
  8.  
  9. void VersionChecker::versionHttpData(int id, bool error)
  10. {
  11. if (id != versionHttpRequestId)
  12. {
  13. return;
  14. }
  15. if(error)
  16. {
  17. latestVersionString = "2.0.0.0";
  18. return;
  19. }
  20. latestVersionString = versionHttp->readAll();
  21. }
  22.  
  23. QString VersionChecker::getLatestVersion()
  24. {
  25. return latestVersionString;
  26. }
To copy to clipboard, switch view to plain text mode 

and how i use it:

Qt Code:
  1. QApplication a(argc, argv);
  2.  
  3. VersionChecker *versionControl = new VersionChecker();
  4. versionControl->checkVersion();
  5. QString latestVersion = versionControl->getLatestVersion();
  6.  
  7. if(latestVersion != _PROGRAM_VERSION)
  8. {
  9. NewVersionAvailableDialog *newVersionDialog = new NewVersionAvailableDialog();
  10. newVersionDialog->setModal(true);
  11. newVersionDialog->setAttribute( Qt::WA_DeleteOnClose );
  12. newVersionDialog->show();
  13. return a.exec();
  14. }
  15.  
  16.  
  17. MainForm w;
  18. w.show();
  19. a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
  20. 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?