Important: Please read the Qt Code of Conduct -

How to perform tasks sequentially? [SOLVED]

  • Hello everyone,

    I am writing a program that download a database from another computer, and display it in a corresponding QML
    view. But when I try to do so with the code below :

    NetworkModule *nwMod = new NetworkModule();

    if(nwMod->getStateReady() == 1)
        DataBase *dbLoad = new DataBase();
        PatientModelSPS *modelsps = NULL;
        modelsps   = dbLoad->LoadDataBaseSPS(modelsps);
        QmlManager *qmlMan = new QmlManager();
        QDeclarativeView view;


    The program starts and stucks after the file was received.

  • Lifetime Qt Champion


    What do you mean by stuck ?

    Also, did you notice that you hide your QDeclarativeView ?

  • yes, I am sorry. But I still have the problem.
    To be clear, I need to :
    first : download a file,
    second : start the User Interface (only if I received the file)

    But it seems that the main.cpp doesn't wait for the downloaded file to be done by the NetworkModule

  • Lifetime Qt Champion

    You don't show anything in your code that suggest a download is in progress anywhere.

    You construct your NetworkModule and then check some state. Does anything happen in between ?

  • When I create the NetworkModule object, it calls the constructor that registers the SIGNALS connected and disconnected.
    Once we're connected, I add a readyread SIGNAL that allows me to receive the file.
    In the main code I gave, if I comment all the lines but the NetworkModule then I have my file downloaded.
    But if I add the other lines, I can't show information contained in the file because the UI lines overlap the NetworkModule that didn't end dowanloading...
    I need something like a semaphore...

  • Lifetime Qt Champion

    What do you use to download the database ?

  • I am using sockets

  • Lifetime Qt Champion

    Without any code, it's getting difficult to help you make a proper "wait until finished" download functionality

  • thanks.

  • Lifetime Qt Champion

    You're download code won't work as your expect it to do (I don't know the size of your database but you'd be lucky if you get it all in one call) There have been several thread's on the subject these last days/weeks, search the forum for them. You should have a look at the Fortune Client/Server examples.

    Also, connect the socket first and then initiate the connection (again I encourage you to read the examples).

    Since you are using signals and slots, you'll need an event loop so either app.exec() or a QEventLoop. Thus you won't be able to achieve what you want to do the way you do it right now.

    I would suggest to make a "manager" object that will start the download and once it's done, create the interface. The "done" being notified by a signal (both success and failure must be handled) once all data have been received. If the download takes time, you could use a progress dialog or a splash screen to let your user know that something is on the way.

    Hope it helps

  • Yeah, I managed to make a draft of a the manager. Now my application is waiting for the database before creating the interface.
    Like you said, I'll need to have a splashcreen to display the downloading of the database as it may take some time...
    thanks a lot.

Log in to reply