Results 1 to 7 of 7

Thread: Bizarre bug with a slot

  1. #1
    Join Date
    May 2006
    Posts
    58
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Bizarre bug with a slot

    I have a function which makes an XML request of a server to request the data for lookup tables. The server responds with an XML message of the data to insert into a local sqlite database.

    On Linux, this all works perfectly.

    On Windows, for some strange reason, the requestFinished signal of the QHttp object fires twice. I have checked, and neither time is it sending in an error code, and the id of the request is the id of the request that I have sent. I have verified that I am not making the request twice.

    In my requestFinished handler, I create a QDomDocument of the received XML, and I fire off a signal to let another class know it can grab the resulting QDomDocument. The slot for that class loops through the document and inserts the data into a SQLIte database.

    The really odd thing is that if I simply comment out the QSqlQuery exec line in this slot's function, the requestFinished signal doesn't fire a second time.

    I have no idea what is going on here. If my slot for requestFinished doesn't return quickly enough, can it cause the signal to somehow fire again?

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

    Default Re: Bizarre bug with a slot

    Could you prepare a minimal compilable example reproducing the problem?

  3. #3
    Join Date
    May 2006
    Posts
    58
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Bizarre bug with a slot

    Quote Originally Posted by wysota View Post
    Could you prepare a minimal compilable example reproducing the problem?
    I'm trying, but I can't even reproduce it in other parts of the same codebase, much less in a pared-down app.

    I keep thinking that maybe I'm attaching to the signal twice, but the only time it fires multiple times is if there's a delay (I replaced my insert statement with just a long sleep, and that caused the same effect)

  4. #4
    Join Date
    May 2006
    Posts
    58
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Bizarre bug with a slot

    Quote Originally Posted by wysota View Post
    Could you prepare a minimal compilable example reproducing the problem?
    OK, after a bit of pain I managed to isolate the problem and produce a compilable example. Note that this bug actually *can* be reproduced under Linux even though I stated earlier that it cannot. You simply have to change the line _sleep(90000) with sleep(90) and this code will produce the same results under Linux.
    Attached Files Attached Files

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

    Default Re: Bizarre bug with a slot

    Well.. this code doesn't compile. It complains _sleep() is undefined. Anyway don't take it personal but sleeping in a slot is a really stupid idea And I can imagine some failsafe mechanism kicks in and emits a signal for the second time because of a timeout or something.

  6. #6
    Join Date
    May 2006
    Posts
    58
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Bizarre bug with a slot

    Quote Originally Posted by wysota View Post
    Well.. this code doesn't compile. It complains _sleep() is undefined. Anyway don't take it personal but sleeping in a slot is a really stupid idea And I can imagine some failsafe mechanism kicks in and emits a signal for the second time because of a timeout or something.
    Regarding compilation, Note my earlier explanation that under Linux you have to remove the "_" from the sleep function and change the argument from microsectonds to seconds.

    At any rate, the sleep is only there to reproduce the bug

    In the actual code, I am taking the XML I received and inserting into a local SQLite database. The insert loop is taking about a minute or so, and that is where I run into this bug.

    If I have an expensive operation to perform as the result of an HTTP request, where else can I execute my code other than in the callback slot? I really don't think re-firing the signal is desirable behavior from the signal/slot mechanism...Is this re-firing documented behavior?

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

    Default Re: Bizarre bug with a slot

    Quote Originally Posted by hardgeus View Post
    At any rate, the sleep is only there to reproduce the bug

    In the actual code, I am taking the XML I received and inserting into a local SQLite database. The insert loop is taking about a minute or so, and that is where I run into this bug.
    So make it last a second or don't insert into the database as a reaction to a timer-based signal. Post an event or use a 0 timeout timer to trigger a deffered call.

    If I have an expensive operation to perform as the result of an HTTP request, where else can I execute my code other than in the callback slot? I really don't think re-firing the signal is desirable behavior from the signal/slot mechanism...Is this re-firing documented behavior?
    It's not the same signal. It might be a signal related to timing out something. Anyway I'm just guessing here. Move the query elsewhere and your problem will go away. Otherwise closely examine the second signal to see if it is a copy of the first one.

Similar Threads

  1. How to declare SLOT as a parameter to member function?
    By QPlace in forum Qt Programming
    Replies: 2
    Last Post: 17th July 2018, 00:41
  2. Problem When Creating my own Slot
    By Fatla in forum Qt Programming
    Replies: 12
    Last Post: 6th June 2008, 14:44
  3. Replies: 2
    Last Post: 23rd May 2008, 13:22
  4. Object::connect: Parentheses expected, slot...
    By bnilsson in forum Qt Programming
    Replies: 5
    Last Post: 5th April 2008, 15:02

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
  •  
Qt is a trademark of The Qt Company.