Results 1 to 6 of 6

Thread: Multi thread problem

  1. #1
    Join Date
    Feb 2006
    Posts
    60
    Thanks
    21
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Multi thread problem

    Hi,
    My app. uses two threads, one to run the kernel(shell) and the other is gui.
    If a long running process is started in GUI, I go to the shell and delete the pointers used by my GUI, the app. crashes.
    So, Is there a clean way(except from copying everything to gui, as the data structures are heavy), to stop the app. from crashing.

    please suggest the possible solutions

    Thanking you,

    regards,
    sree

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Multi thread problem

    Why do you have to delete those pointers? Maybe the GUI should be responsible for cleaning up the memory?

  3. #3
    Join Date
    Feb 2006
    Posts
    60
    Thanks
    21
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Multi thread problem

    there will be some case when i have to delete the complete pointers in gui and set them fresh, if some things are changed from shell.

    Then if an operation is already running in gui, the gui crashes

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Multi thread problem

    Quote Originally Posted by sreedhar
    Then if an operation is already running in gui, the gui crashes
    So you have to either wait for the GUI to finish or make the GUI delete those objects when it doesn't need them anymore.

  5. The following user says thank you to jacek for this useful post:

    sreedhar (28th June 2006)

  6. #5
    Join Date
    Jan 2006
    Posts
    75
    Thanks
    3
    Thanked 5 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Multi thread problem

    http://doc.trolltech.com/4.1/qobject.html#deleteLater

    for any object that are extend from QObject, use the deleteLater function rather than directly use the [delete] operator

  7. The following user says thank you to ball for this useful post:

    sreedhar (28th June 2006)

  8. #6
    Join Date
    Jun 2006
    Posts
    11
    Thanked 4 Times in 4 Posts

    Default Re: Multi thread problem

    One solution would be to reference-count the objects that both the shell and the GUI will need to access, and instead of simply calling delete on them you check how many others are refering to it. If it's 0 you delete, if not you just decrement the reference count. So when whatever happens in the shell and you need to delete the pointers you first check if they are used and if not go ahead and delete, but if they are you just create new objects.

    You might also be interested in QPointer, QSharedDataPointer or one of the Implicitly Shared Classes.

  9. The following user says thank you to eriwik for this useful post:

    sreedhar (28th June 2006)

Similar Threads

  1. Thread problem with windows
    By vratojr in forum Qt Programming
    Replies: 17
    Last Post: 16th June 2006, 08:34
  2. Problem in creating thread in GUI application
    By jyoti kumar in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2006, 12:05
  3. [QT4] QThread and printing a QList<QPixmap>
    By KShots in forum Qt Programming
    Replies: 3
    Last Post: 24th April 2006, 21:44
  4. Thread Problem
    By qball2k5 in forum Qt Programming
    Replies: 2
    Last Post: 12th April 2006, 17:31
  5. Problem building Qt4.1.0 with thread support on windows XP
    By pavithra in forum Installation and Deployment
    Replies: 1
    Last Post: 1st April 2006, 11:35

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.