Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. 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
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 2.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AshwinDubey
    wrote on last edited by
    #1

    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..
    
    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      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?

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • F Offline
        F Offline
        florent.revelut
        wrote on last edited by
        #3

        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
        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved