waiting for a signal

前端 未结 3 419
悲哀的现实
悲哀的现实 2020-12-06 11:26

I am working on an application which uploads the content of the file to server.

To upload the file to server I am using ‘QNetworkAccessManager’ class. Since it works

3条回答
  •  囚心锁ツ
    2020-12-06 11:52

    From what I can see from your code, you're executing a QEventLoop but you're not actually connecting its "quit" slot to any signal. Take the below as an example, login is a QHttp - and the code is taken from something different - but the principle applies.

    /* Create the QEventLoop */
    QEventLoop pause;
    /* connect the QHttp.requestFinished() Signal to the QEventLoop.quit() Slot */
    connect(&login, SIGNAL(requestFinished( int, bool )), &pause, SLOT(quit()));
    /* The code that will run during the QEventLoop */
    login.request(header,&logmein,&result);
    /* Execute the QEventLoop - it will quit when the above finished due to the connect() */
    pause.exec();
    

    This could be applied to your code, if I'm not mistaken, like this...

    /* connect the signal to the relevant slot */
    connect(&mNetworkManager, SIGNAL(finished( QNetworkReply )), &EventLoop, SLOT(quit()));
    /* Execute the code that will run during QEventLoop */
    responce = mNetworkManager.put(request, data);
    /* Execute the QEventLoop */
    EventLoop.exec();
    

    Apologies if I've mistaken your query! I'm only getting to grips with qt again after a break, but I believe this is what you mean! Good luck!

提交回复
热议问题