Results 1 to 10 of 10

Thread: QTimer and modeless dialog

  1. #1
    Join Date
    Jul 2011
    Posts
    15
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QTimer and modeless dialog

    Hi,

    I was faced with a very strange behavior. Not critical as I can do it other way but I would like to know why it happens.
    I have a qt designer class that I use as a modeless dialog In a mainwindow application.

    If i defined in my mainwindow.h a pointer to a QTimer variable my application always gives segfault at the call of the modeless dialog show(), regardless i do not even use or mention my QTimer pointer anywhere else in the program. Any no modeless dialogs work just fine.
    For my application to work I only need to comment the Qtimer *timer declaration in mainwindow.h

    I have no problem if i just define the timer in any of the mainwindow functions in mainwindow.cpp, and that's why this problem is not critical, but for me, at least, is very strange. It took me a large amount of hours to discovered that the segfault was due to the fact that I had a QTimer pointer defined in mainwindow.h as I couldn't spot any relation with that declaration, not even used anywhere else, and the modeless dialog.

    kind regards,

  2. #2
    Join Date
    May 2011
    Posts
    239
    Thanks
    4
    Thanked 35 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Symbian S60

    Default Re: QTimer and modeless dialog

    I would suggest that this happens because of either
    1) A corrupted build - try a clean and rebuild

    2) A compiler or linker bug

    3) Some other hidden bug is the real culprit; this piece of code just is a catalyst

    ...Of course, you should not have unused variables in your code... Perhaps the problem would go away if you used the variable.

  3. #3
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTimer and modeless dialog

    having an uninitialised pointer anywhere doesn't cause a seg fault inherently. I would suggest you still have a problem somewhere
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QTimer and modeless dialog

    To say what the problem is, we should be able to see your code.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Jul 2011
    Posts
    15
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTimer and modeless dialog

    Quote Originally Posted by high_flyer View Post
    To say what the problem is, we should be able to see your code.
    I understand that. However it is a huge amount of code. I'm going to try to replicate the problem with a small ad-hoc application as I'm really worried about having an hidden bug completely unrelated. I'm assembling an application to be used by many co-workers in academic and scientific environment and it is really big.

    If I'm able to replicate the problem with a smaller code sample I'll post it again.

    Many thanks.

  6. #6
    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: QTimer and modeless dialog

    Sometimes it is enough to run your program with a debugger and post the backtrace of the crash. Just be sure to build the application in debug mode.
    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.


  7. #7
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QTimer and modeless dialog

    a full clean and a rebuild might also help.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  8. #8
    Join Date
    Jul 2011
    Posts
    15
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTimer and modeless dialog

    Quote Originally Posted by high_flyer View Post
    a full clean and a rebuild might also help.
    I've tried that the first time I encountered the problem.
    Meanwhile i was able to pinpoint the problem. This is the first time I use modeless dialogs and I was copying the qt documentation example
    Qt Code:
    1. void EditorWindow::find()
    2. {
    3. if (!findDialog) {
    4. findDialog = new FindDialog(this);
    5. connect(findDialog, SIGNAL(findNext()), this, SLOT(findNext()));
    6. }
    7.  
    8. findDialog->show();
    9. findDialog->raise();
    10. findDialog->activateWindow();
    11. }
    To copy to clipboard, switch view to plain text mode 
    so I have a slot in my mainwindow

    Qt Code:
    1. void MainWindow::select_singlevaluesfields()
    2. {
    3.  
    4. if(!channelldialog){
    5. channelldialog=new channelWindow(this);
    6. channelldialog->cil=&cil;
    7. channelldialog->nchannels=nchannels;
    8. channelldialog->fillsinglevalues();
    9.  
    10. }
    11. QDateTime x,y;
    12. x.setTimeSpec(Qt::UTC); y.setTimeSpec(Qt::UTC);
    13. GetTimeInterface(&x,&y);
    14. channelldialog->Itime=x;
    15. channelldialog->Ltime=y;
    16. channelldialog->setTimeInterface(x,y);
    17. channelldialog->show();
    18. channelldialog->raise();
    19. channelldialog->activateWindow();
    20.  
    21. }
    To copy to clipboard, switch view to plain text mode 

    and in mainwindow .h I have defined
    Qt Code:
    1. channelWindow *channelldialog;
    To copy to clipboard, switch view to plain text mode 
    It seems that sometimes the test !channelldialog is always false even in the first call (this occurs anytime I have also a QTimer pointer in the main window) so any uses of the channelldialog points to nowhere and the segfault. the problem goes away is i do not rely in the if(!channelldialog) condition test and add the channelldialog=new channelWindow(this); in the mainwindow constructor.


    Added after 6 minutes:


    oops, I've just noticed there is a huge difference between my code and the qt code example. My bad.
    Last edited by artome; 2nd July 2012 at 16:18.

  9. #9
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QTimer and modeless dialog

    It seems that sometimes the test !channelldialog is always false
    Well, where did you initialize it?
    If you have an uninitialized pointer, it indeed points to what ever garbage its address has when the variable is defined.
    If you initialize it in your constructor, you wont have undefined behavior.
    Qt Code:
    1. MyClass::MyClass() : MyBaseClass(),
    2. m_pPointer(NULL)
    3. {}
    To copy to clipboard, switch view to plain text mode 

    will ensure your pointers is NULL at startup.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  10. The following user says thank you to high_flyer for this useful post:

    artome (2nd July 2012)

  11. #10
    Join Date
    Jul 2011
    Posts
    15
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTimer and modeless dialog

    The problem is now solved just added, as suggested high_flyer the initialized to NULL in mainwindow constructor the channelldialog pointer.

    many thanks to him and to all the others that offered further insight into my problem.

    Best wishes.

Similar Threads

  1. modeless dialog in qt dll loaded in existing non qt app
    By elizabeth.h1 in forum Qt Programming
    Replies: 2
    Last Post: 28th July 2009, 12:49
  2. How to delete modeless dialog?
    By rajesh in forum Qt Programming
    Replies: 15
    Last Post: 16th June 2009, 12:19
  3. Modeless dialog disappearing
    By Raccoon29 in forum Qt Programming
    Replies: 4
    Last Post: 15th September 2007, 11:38
  4. modeless dialog closed signal?
    By gfunk in forum Qt Programming
    Replies: 2
    Last Post: 5th January 2007, 00:40
  5. modeless dialog
    By mhoover in forum Newbie
    Replies: 2
    Last Post: 23rd March 2006, 22:56

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.