Results 1 to 5 of 5

Thread: processEvents preventing class from destruction?

  1. #1
    Join Date
    Oct 2007
    Posts
    8
    Thanks
    1

    Unhappy processEvents preventing class from destruction?

    As I implemented my first QDSService, I thought the application would last forever after the first request for it. It was somehow true, because that single instance was staying alive for how many requests I did.
    However, I made a second service, a lot simpler, and the application was created/destroyed at each service solicitation.

    It turns out that the line:

    QCoreApplication:: processEvents();

    was preventing the application to be destroyed (i.e. no destructor called).
    Since this line is needed to help synchronizing QHttp response, what exactly is wrong? The service actually responds correctly.. it just not get destroyed after that.

    By the way, since I have two services that are so often used, I'd like to make them startup as soon as the mobile loads. I think, with this, it will only get instantiated once. How can I achieve that?
    I tried adding the application name in tasks.cfg, but the application didn't get instantiated.

    Thanks in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: processEvents preventing class from destruction?

    If you process events all the time, you don't give the application a chance to actually quit the event loop because you keep triggering it by calling processEvents(). Instead you should use signals and slots with QHttp and not call processEvents().

  3. #3
    Join Date
    Oct 2007
    Posts
    8
    Thanks
    1

    Default Re: processEvents preventing class from destruction?

    Sorry for the lack of details, but I actually need to synchronize the qHttp usage, since it is called from a service class.
    Let me try to explain in code:

    1. An application calls
    Qt Code:
    1. QDSServiceInfo service("getAllUsers", "BackendCommunication");
    2. QDSAction* qdsAction = new QDSAction(service);
    3. qdsAction->invoke();
    To copy to clipboard, switch view to plain text mode 

    2. In the BackendCommunication class, I do something like this:
    Qt Code:
    1. http->request(header, QByteArray().append(msg));
    2. // wait until request is done
    3. while (responses[http] == "") {
    4. QCoreApplication::processEvents();
    5. }
    6. QString response = responses[http];
    To copy to clipboard, switch view to plain text mode 

    That is why I used processEvents - the busy loop up there. My doubt was why it is preventing the application to quit, if the application eventually exits the method. I can successfully respond the response to the calling application.

    Regarding that service lifecycle, is there something to do to avoid instancing every time? I need to have the BackendCommunication instance running as soon as possible (since it should be able to do some things without user input)

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: processEvents preventing class from destruction?

    So change your code - divide it into parts and start the second part after receiving a signal from the QHttp object started in the first part. You'll be eating less cpu cycles and at the same time fix your problem.

  5. #5
    Join Date
    Oct 2007
    Posts
    8
    Thanks
    1

    Default Re: processEvents preventing class from destruction?

    I see... maybe putting this as a service wasn't the best idea...

    But anyways, about instantiating the application right in the start, I have attempted two things:
    1. adding the application in Tasks.cfg
    2. adding a etc/default/Trolltech/Launcher configuration file with the application (according to
    startupapplications.html)

    But the application wasn't started. Can you give more details on this?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.