Results 1 to 8 of 8

Thread: MessageBox appearnig twice.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2010
    Posts
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: MessageBox appearnig twice.

    Hi all,

    Any idea, how to avoid double appearance of messagebox ?
    I have got stuck due to this weird behavior.

    Please help..

  2. #2
    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: MessageBox appearnig twice.

    I take it that validateInput() is a slot.
    Can you show which signals did you connect to this slot?

    It looks like you have connected several objects to this slot, and any of these signals trigger the slot, and since you are doing a lot of checking on various widgets in the slots it self, it is very well possible that multiple conditions are true, and thus trigger multiple message boxes.
    ==========================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.

  3. #3
    Join Date
    Apr 2010
    Posts
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: MessageBox appearnig twice.

    Quote Originally Posted by high_flyer View Post
    I take it that validateInput() is a slot.
    Can you show which signals did you connect to this slot?

    It looks like you have connected several objects to this slot, and any of these signals trigger the slot, and since you are doing a lot of checking on various widgets in the slots it self, it is very well possible that multiple conditions are true, and thus trigger multiple message boxes.
    Hi,
    validateInput() is not a slot but called by slot on_addButton_clicked() when "Add Button" is clicked. As shown in below code.

    Here are few thing about application, which may help to understand the issue.
    1). I have created QMainWindowGUI with various menu and submenus.
    2). On clicking Add -> Expense -> Add Single Entry I am creating SingleEntry widget with QMainWindow as parent where in all text boxes, dropdown and button stuff comes into picture.
    3). On this singleentry widget while performing validation this issue is occurring.
    4). setupSingleEntry function is called when "Add Single Entry" submenu option is clicked.

    Let me know if further input is required.

    Qt Code:
    1. void SingleEntry::setupSingleEntry(){
    2. setupSingleEntrySignalSlots();
    3. populateExpenseCategory();
    4. ui->expenseDate->setDate(QDate::currentDate());
    5. ui->expenseDate->setMaximumDate(QDate::currentDate()); /* Restrict user from selecting Future Dates */
    6. }
    7.  
    8. void SingleEntry::setupSingleEntrySignalSlots(){
    9. connect(ui->expenseClassCombo,SIGNAL(currentIndexChanged(int)),this,SLOT(on_expenseClassCombo_currentIndexChanged()));
    10. connect(ui->adjustmentCheckBox,SIGNAL(clicked()),this,SLOT(on_adjustmentCheckBox_clicked()));
    11. connect(ui->addButton,SIGNAL(clicked()),this,SLOT(on_addButton_clicked()));
    12. }
    13.  
    14. void SingleEntry::on_addButton_clicked(){
    15. if(validateInput()){
    16. QMessageBox::information(0,"Success","Validation Successful");
    17. }
    18. else{
    19.  
    20. }
    21. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Apr 2010
    Posts
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: MessageBox appearnig twice.

    Hi All,

    Issue got resolved. Actual problem was in setupSingleEntrySignalSlots()function. I am connecting addButton with SLOT on_addButton_clicked() second time. First time it is already done Qt with in-built function connectSlotsByName(). So on_addButton_clicked() was getting called twice and hence appearance of messagebox .

    Thanks for your suggestions.

    Quote Originally Posted by ronak.vashi View Post
    Hi,
    validateInput() is not a slot but called by slot on_addButton_clicked() when "Add Button" is clicked. As shown in below code.

    Here are few thing about application, which may help to understand the issue.
    1). I have created QMainWindowGUI with various menu and submenus.
    2). On clicking Add -> Expense -> Add Single Entry I am creating SingleEntry widget with QMainWindow as parent where in all text boxes, dropdown and button stuff comes into picture.
    3). On this singleentry widget while performing validation this issue is occurring.
    4). setupSingleEntry function is called when "Add Single Entry" submenu option is clicked.

    Let me know if further input is required.

    Qt Code:
    1. void SingleEntry::setupSingleEntry(){
    2. setupSingleEntrySignalSlots();
    3. populateExpenseCategory();
    4. ui->expenseDate->setDate(QDate::currentDate());
    5. ui->expenseDate->setMaximumDate(QDate::currentDate()); /* Restrict user from selecting Future Dates */
    6. }
    7.  
    8. void SingleEntry::setupSingleEntrySignalSlots(){
    9. connect(ui->expenseClassCombo,SIGNAL(currentIndexChanged(int)),this,SLOT(on_expenseClassCombo_currentIndexChanged()));
    10. connect(ui->adjustmentCheckBox,SIGNAL(clicked()),this,SLOT(on_adjustmentCheckBox_clicked()));
    11. connect(ui->addButton,SIGNAL(clicked()),this,SLOT(on_addButton_clicked()));
    12. }
    13.  
    14. void SingleEntry::on_addButton_clicked(){
    15. if(validateInput()){
    16. QMessageBox::information(0,"Success","Validation Successful");
    17. }
    18. else{
    19.  
    20. }
    21. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. set Bold to MessageBox particular Text
    By BalaQT in forum Qt Programming
    Replies: 2
    Last Post: 5th November 2009, 11:53
  2. MessageBox Validation
    By fortyhideout12 in forum Newbie
    Replies: 10
    Last Post: 2nd September 2009, 17:14
  3. Replies: 1
    Last Post: 21st April 2008, 22:43
  4. default on focus different item in messagebox?
    By gfunk in forum Qt Programming
    Replies: 1
    Last Post: 26th October 2007, 05:54
  5. QSA 1.2.1 && MessageBox
    By xk in forum Newbie
    Replies: 0
    Last Post: 20th April 2006, 17:30

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.