Qt download example



  • http://doc.qt.io/qt-5/qtnetwork-download-main-cpp.html

    Can this be converted to a function for an existing project? I'm struggling with how to do so. It works great as a standalone program.


  • Qt Champions 2017

    Hi
    Yes, it should be reusable without much fuss. except, make sure to place the class definitionsin a .h file
    as sample uses trick to get the moc tool (to allow for signals) to process the .CPP file.
    So best to include in a .h instead for reuse.
    Then there is the scope thing to be aware of.

    in sample, it does

    int main(int argc, char **argv)
    {
        QCoreApplication app(argc, argv);
    
        DownloadManager manager;
        QTimer::singleShot(0, &manager, SLOT(execute()));
    
        app.exec();
    }
    

    This you cannot directly use in function as manager will run out of scope and die so you have to new it.

        DownloadManager *manager = new DownloadManager(this);
        QTimer::singleShot(0, manager, SLOT(execute()));
    

    Else please tell what is causing issues so we can help.



  • Thank you for the help.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.