After slot execution control not coming back to the file from where function cald (func present in same file as that of slot, to set "signals to slots



  • Hi, I am calling a function in which I’m setting the URL and signal & slots..the slot definitions and this function where setting the slot are in a file and I’m calling the function from another file. However after the execution of slot correctly the control doesn’t come back to the file from where the function was called. If I close the simulator then only the control comes back to another file and debug statements there are executed…why is it so…

    Followin is the code of file widget.cpp from where I'm calling the function execute of Dmanager:-

    @
    void initiateSubscription(QPlan plan)
    {
    DownloadManager Dmanager;

        qDebug()<<"In initSubscription ";
    
        url1="http://202.87.41.147/hungamaone/get_session.php";
    
        Dmanager.execute();
    

    qDebug()<<"BAck In initSubscription ";

    }
    

    @
    Class declaration in http.h is as follows :
    @
    class DownloadManager: public QObject
    {
    Q_OBJECT
    QNetworkAccessManager manager;
    QList<QNetworkReply *> currentDownloads;

    public:
    DownloadManager();
    void doDownload(const QUrl &url);
    QString saveFileName(const QUrl &url);
    bool saveToDisk(const QString &filename, QIODevice *data);

    public slots:
    void execute();
    void downloadFinished(QNetworkReply* reply);
    };
    @

    Contents of http.cpp are as follows:
    @
    void DownloadManager::execute()
    {
    qDebug()<<"In execute of Downloadmanager ";

        QUrl url("http://202.87.41.147/hungamaone/get_session.php");
    
        doDownload(url);
    

    }

    void DownloadManager::doDownload(const QUrl &url)
    {
    QNetworkRequest request(url);

    QEventLoop loop;
    
    qDebug()<<"In doDownload";
    QNetworkReply*reply = manager.get(request);
    

    loop.exec();

    currentDownloads.append(reply);
    }

    void DownloadManager::downloadFinished(QNetworkReply* reply)
    {
    QByteArray data=reply->readAll();
    QString str(data);

       qDebug()<<"In downloadFinished ";
    
      strR=str;
    qDebug()<<"Reply in downloadFinished slot is "<<strR;
    

    }
    @

      after call to Dmanager.execute() from widget.cpp control comes to execute function in http.cpp. Then it goes to doDownload. Then slot downloadFinished gets executed and it prints "Reply in downloadFinished slot is "u5q4n15o9mkadss2ho7enivu67" ". However after this the control doesn't go back to the statement "qDebug()<<"BAck In initSubscription ";" which is after the call to execute in widget.cpp. Only when I close the simulator does the control comes to this statement after call to execute and prints that debug statement. I want the control to come back here without being required to close the simulator....Kindly let me know..


  • Hi,

    I don't relly get your point. Can you please post some code snipüpet and show there, what you do and what does not work?



  • Quick answer, it's fairly hard to understand your problem.

    Just as a reminder :

    • slot is just a regular method, which can be magically called by framework when a signal connected to this slot is emitted. It's a convenient way in multithreaded environement to have cross-threads messaging.
    • a signal is just (from the external) a way to notify (think broadcast) information
    • linking the slot and the signal is done with a QObject static method (connect)

    if you want some help, you'll have

    • to rephrase clearly what you're trying to do
    • provide some code to analyze
    • explain what you expect and what you observe

Log in to reply
 

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