Results 1 to 10 of 10

Thread: Qmessagebox cant stop looping

  1. #1
    Join Date
    Jul 2009
    Posts
    55
    Thanks
    3

    Default Qmessagebox cant stop looping

    the qmessagebox is in the below void that will loop every 5 sec. and so the messagebox will popup every 5 sec as well, is there a way to let the message box just pop up once? but at the same time, the void is still looping every 5 sec??

    Qt Code:
    1. void Node::updateData(int index)
    2. {
    3. //setNodeData(index);
    4.  
    5. DB_OPEN
    6. NodeDb::DATA *pData;
    7. pNodeDb->getData(index, &pData);
    8.  
    9. nodeData.temp= pData->temp;
    10. nodeData.voltage = pData->voltage;
    11. nodeData.type = pData->type;
    12. nodeData.strength = pData->strength;
    13. nodeData.re = pData->re;
    14. nodeData.t_time_on = pData->t_time_on;
    15.  
    16. nodeData.fadeNumber=pData->fadeNumber;
    17. nodeData.fadeTime =pData->fadeTime ;
    18. nodeData.newNode=pData->newNode;
    19. nodeData.deletedNode=pData->deletedNode;
    20.  
    21. setColor(nodeData.type);
    22.  
    23. if (pData->status == NodeDb::DS_MOVE)
    24. {
    25. newPos.setX(pData->xpos);
    26. newPos.setY(pData->ypos);
    27. advance();
    28. }
    29.  
    30. if (nodeData.addr==0){
    31. nodeData.fadeNumber = 255;//pData->fadeNumber;
    32. //ap_counter=apcount;
    33. updated = true;
    34. update();
    35. if (!updateTimerId)
    36. {
    37. updateTimerId = startTimer(200);
    38. }
    39. }
    40.  
    41. timeStamp.restart();
    42.  
    43. if (nodeData.addr!=0)
    44. {
    45. updated = true;
    46. update();
    47. if(nodeData.temp > ((alertTemp*9)/5+32.0)||(edStrength > alertDistance))
    48. {
    49. QSound::play("sound/alert.wav");
    50. QMessageBox::critical(NULL, tr("Alert"), tr("High temperature is being detected!!!"));
    51. }
    52. }
    53. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qmessagebox cant stop looping

    normal program operation ..
    use static int variable ..

    Qt Code:
    1. static int count = 0;
    2. if(nodeData.temp > ((alertTemp*9)/5+32.0)||(edStrength > alertDistance))
    3. {
    4. QSound::play("sound/alert.wav");
    5. if(count != 0){
    6. QMessageBox::critical(NULL, tr("Alert"), tr("High temperature is being detected!!!"));
    7. count + = 1;
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 
    "Behind every great fortune lies a crime" - Balzac

  3. #3
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qmessagebox cant stop looping

    Or define your count variable in the class, thereby keeping the function reentrant.

  4. #4
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qmessagebox cant stop looping

    Showing a message box, waits untill you manually close that. This is how GUI event loop works. So you can do one thing.
    Popup the message box. And close it by code, don't wait user to click on that to close it. Something like this:

    Qt Code:
    1. QMessageBox msgBox(bla,bla);
    2. msgBox.show();
    3. wait(n);
    4. msgBox.close();
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jul 2009
    Posts
    55
    Thanks
    3

    Default Re: Qmessagebox cant stop looping

    Quote Originally Posted by wagmare View Post
    normal program operation ..
    use static int variable ..

    Qt Code:
    1. static int count = 0;
    2. if(nodeData.temp > ((alertTemp*9)/5+32.0)||(edStrength > alertDistance))
    3. {
    4. QSound::play("sound/alert.wav");
    5. if(count != 0){
    6. QMessageBox::critical(NULL, tr("Alert"), tr("High temperature is being detected!!!"));
    7. count + = 1;
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 
    hmmm the messagebox now doesnt appear..

  6. #6
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qmessagebox cant stop looping

    I think your question is misunderstood. Got diverse replies.

  7. #7
    Join Date
    Jul 2009
    Posts
    55
    Thanks
    3

    Default Re: Qmessagebox cant stop looping

    Quote Originally Posted by yogeshgokul View Post
    Showing a message box, waits untill you manually close that. This is how GUI event loop works. So you can do one thing.
    Popup the message box. And close it by code, don't wait user to click on that to close it. Something like this:

    Qt Code:
    1. QMessageBox msgBox(bla,bla);
    2. msgBox.show();
    3. wait(n);
    4. msgBox.close();
    To copy to clipboard, switch view to plain text mode 
    but i wan the user to close it.

  8. #8
    Join Date
    Jul 2009
    Posts
    55
    Thanks
    3

    Default Re: Qmessagebox cant stop looping

    Qt Code:
    1. if (nodeData.addr!=0)
    2. {
    3. updated = true;
    4. update();
    5. static int count = 0;
    6. if(nodeData.temp > ((alertTemp*9)/5+32.0)||(edStrength > alertDistance))
    7. {
    8. QSound::play("sound/alert.wav");
    9. if(count == 0)
    10. {
    11. QMessageBox::critical(NULL, tr("Alert"), tr("High temperature is being detected!!!"));
    12. count++;
    13. }
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 

    it work with this. but still have problem. if the user never press OK, many more messagebox window will popup.

  9. #9
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qmessagebox cant stop looping

    Do the count++ before you open the messagebox.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  10. #10
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qmessagebox cant stop looping

    it work with this. but still have problem. if the user never press OK, many more messagebox window will popup.
    use isVisible() condition along with the count condition ...

    hey franz is right .. use the count before showing ..
    Last edited by wagmare; 7th August 2009 at 07:47. Reason: franz reply ..
    "Behind every great fortune lies a crime" - Balzac

Similar Threads

  1. Replies: 7
    Last Post: 12th January 2011, 22:01
  2. QMessageBox misbehaves after QFileDialog call
    By MikeG in forum Qt Programming
    Replies: 8
    Last Post: 2nd June 2009, 10:17
  3. setting background color of QMessageBox
    By wagmare in forum Qt Programming
    Replies: 7
    Last Post: 23rd May 2009, 13:26
  4. ¿How to stop thread that is capturing from a webcam?
    By JoseTlaseca in forum Qt Programming
    Replies: 8
    Last Post: 28th August 2008, 04:45
  5. QMessageBox problem in Qtopia
    By jogeshwarakundi in forum Qt for Embedded and Mobile
    Replies: 5
    Last Post: 8th February 2008, 09:22

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.