Results 1 to 15 of 15

Thread: window freezed

  1. #1
    Join Date
    Jul 2007
    Posts
    21
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Unhappy window freezed

    Hello,

    I've programming in c++ with Qt 4.2.3. My problem is the following:

    I've a window that is refreshing by another thread using signal-slot method. In a moment, without explanation, the window is freezed and never is refreshed. This window has some textfields that contains qstrings.

    When the window is freezed, the rest of the application continue working properly.

    ¿What can i investigate to find the problem? I do not know where to start looking for the problem. Please, help me.

    If you need another information to helpl me, please, ask me.

    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: window freezed

    Share some relevant code, please.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jul 2007
    Posts
    21
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: window freezed

    It's not easy, but I try to explain:

    The window is created as a library that is used as object in the main application.

    Before the arrival of a message from the main aplicacatio, updated a number of areas of the window:

    Qt Code:
    1. switch (consoleId) {
    2. case 1:
    3. {
    4. itsRoleWindow->writeTF_roleConsole01(strdup(static_cast<char*> (roleActiveName[consoleId - 1])));
    5. break;
    6. }
    7. case 2:
    8. {
    9. itsRoleWindow->writeTF_roleConsole02(strdup(static_cast<char*> (roleActiveName[consoleId - 1])));
    10. break;
    11. }
    12. [...]
    To copy to clipboard, switch view to plain text mode 

    Let's see what happens in the window:

    Qt Code:
    1. void roleWindow::writeTF_roleConsole01(char* c)
    2. {
    3. GetForm()->setText(c,1);
    4. }
    To copy to clipboard, switch view to plain text mode 

    The class that receives it does this:

    Qt Code:
    1. void impl_role::setText(char* c, int i)
    2. {
    3. emit(signalSetText(c,i));
    4. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. connect( this, SIGNAL(signalSetText(char*, int)), this, SLOT(slotSetText(char*, int)) );
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void impl_role::slotSetText(char* c, int i)
    2. {
    3. switch(i) {
    4. case 1: TF_roleConsole01->setText(c); break;
    5. case 2: TF_roleConsole02->setText(c); break;
    6. case 3: TF_roleConsole03->setText(c); break;
    7. case 4: TF_roleConsole04->setText(c); break;
    8. case 5: TF_roleConsole05->setText(c); break;
    9. case 6: TF_roleConsole06->setText(c); break;
    10. case 7: TF_roleConsole07->setText(c); break;
    11. default: break;
    12. };
    13. delete (c);
    14. }
    To copy to clipboard, switch view to plain text mode 

    with each TF_roleConsole0x really is ui-> TF_roleConsole0x;

    Therefore, writes directly to each window Textfield.

    I hope I explained more or less.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: window freezed

    Aside from the memory leak this looks ok, in the sense of nothing there would cause a window to "freeze".

    Cheers,
    _

  5. #5
    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: window freezed

    You said something about threads, can we see their definition? Are there any direct calls to GUI objects from threads other than the main UI thread?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Jul 2007
    Posts
    21
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: window freezed

    The textfield of the ui only is accessed by the method of the main application described on the second reply:

    <code>switch (consoleId) {
    case 1:
    {
    itsRoleWindow->writeTF_roleConsole01(strdup(static_cast<char*> (roleActiveName[consoleId - 1])));
    break;
    }
    case 2:
    {
    itsRoleWindow->writeTF_roleConsole02(strdup(static_cast<char*> (roleActiveName[consoleId - 1])));
    break;
    }
    [...]</code>

  7. #7
    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: window freezed

    Ok but there are no threads here.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Jul 2007
    Posts
    21
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: window freezed

    Ok,

    I've read the complete project and this method is called from 2 differents callback methods from two different objects.

    ¿Is it possible that i need a mutex in the method shared by the 2 callbacks?

    (sorry for my mistake at explain my problem)

  9. #9
    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: window freezed

    You don't need any mutexes if your program does not have more than one thread. So far we have seen no evidence of more than one thread in your program.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Jul 2007
    Posts
    21
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: window freezed

    I'm not sure but each callback method i think, generates a thread because it's possible to receive the two different messages at the same time.

    If this two callback methods, use the method that writes in the textfields, i think i need to use a mutex to prevent...

    Am i in an error?

  11. #11
    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: window freezed

    Quote Originally Posted by jrodway View Post
    I'm not sure but each callback method i think, generates a thread because it's possible to receive the two different messages at the same time.
    I don't know what is the origin of those callbacks but if this is purely Qt code, then there are no threads involved. If there are threads involved, then you can't call any UI-related code from within those callbacks.
    Last edited by wysota; 3rd September 2014 at 13:38.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #12
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: window freezed

    I'm not sure but each callback method i think, generates a thread because it's possible to receive the two different messages at the same time.
    Signals and slots within the GUI do not use threads. I don't think you really understand what "thread" means. In the Qt GUI, everything is queued, and events (including slots) are executed in a sequence. It is impossible for two "messages" (whatever those are) to be received at the same time. One will be received and put into the event queue first, followed by the second one, and the code for them will be executed in the order they were put into the queue.

    The handlers for some events (like paintEvent()) will execute the event only once and remove extra copies from the queue to avoid unnecessary processing, but in general things in the event queue are executed in first-in, first-out order.

  13. #13
    Join Date
    Jul 2007
    Posts
    21
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: window freezed

    I'm sorry, but i use only qt code with the ui. The rest of the application use Threads posix.

    I've got two threads in the main application that try to modify the textfields of the ui. is it possible that i need a mutex to avoid the freeze of the window?

    Thanks for your opinions.

  14. #14
    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: window freezed

    Quote Originally Posted by jrodway View Post
    I've got two threads in the main application that try to modify the textfields of the ui. is it possible that i need a mutex to avoid the freeze of the window?
    No, you cannot access any QObject from any thread other than the thread it belongs to (meaning the application thread in case of Qt widgets) and there is no way to work around this using mutexes. If there are threads involved, you need to change your application design so that those extra threads post messages to the UI thread and then the UI thread modifies state of the wigdets.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  15. #15
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: window freezed

    I think the signal/slot connection in the code above should take care of crossing the thread boundary properly, i.e. it should become a Qt::QueuedConnection.
    But you can try to specify that explictly as the fifth argument to connect().

    Independently I would strongly recommend to make the char* -> QString conversion somewhere before emitting the signal, so that the thread which created the array can delete it as well.

    And, as mentioned earlier, it should do that using the correct delete operator.

    Cheers,
    _

Similar Threads

  1. Replies: 2
    Last Post: 14th January 2013, 07:07
  2. Replies: 6
    Last Post: 9th November 2011, 04:31
  3. Replies: 2
    Last Post: 17th February 2011, 12:30
  4. Make first column freezed in QTableView
    By gutiory in forum Qt Programming
    Replies: 2
    Last Post: 20th December 2010, 06:53
  5. Replies: 11
    Last Post: 4th June 2008, 07:22

Tags for this Thread

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.