Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to make version checking success?



  • Hi, I was sharing my application to users from Internet.
    I wonder how many times that people used my app.
    So I make a new url by url-shorter : reurl.cc , and put it in my code.
    When people launch my app, my app will first visit the url to get html then parse the version number in the html content.
    Therefore, I can get the visit number by reurl.cc service.

    But the truth is, it failed.
    I has about 4500 download times, but the visit number only few hundreds.
    I don't know which one is the reason:
    1.My app not even launch success, so version checking also failed.
    2.My version checking code has problem.
    3.Other reasons.

    Here is my checking codes:

    void CheckVersionThread::run(){
        QNetworkAccessManager manager;
        QNetworkReply *reply = manager.get(QNetworkRequest(QUrl("https://reurl.cc/xxxxxxxxxxxxxxx")));
    
        QEventLoop event_loop;
        QObject::connect(reply , SIGNAL(finished()),
                &event_loop, SLOT(quit()));
        QTimer::singleShot(2000, reply, SLOT(abort()));
    
        event_loop.exec();
    
        QString htmlString{reply->readAll()};
    
        reply->close();
        reply->deleteLater();
        manager.deleteLater();
    
    //parse  html text content. in htmlString .......................
    //skip...........
    }
    

    Any suggestion for me?
    Thank you for your reading.


  • Moderators

    @pachisuro4096
    oh my goodness where to begin.

    • Using threads when not needed (asynchronous api)
    • forcing synchronous behaviour on asynch api
    • overwriting run as threading method
    • not using the exec() of QThread class but using an additional QEventloop
    • calling deleteLater on a stack variable

    the problem is probably your timeout 2 seconds could be to short


Log in to reply