Results 1 to 20 of 21

Thread: alternative to QMessageBox

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    106

    Default alternative to QMessageBox

    In my application I indicate to the user that an action has been performed by using QMessageBox.
    But the drawback is that it stops the appliction and requires the user to click OK to proceed.
    I would like to display a window with a message for say 1 second and then remove it and proceed with the processing.

    Can you point me to the docs ? or give me a hint ?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: alternative to QMessageBox

    Make a dialog with a timer and connect its timeout() signal to dialogs accept() slot.

  3. The following user says thank you to wysota for this useful post:

    incapacitant (19th May 2006)

  4. #3
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    106

    Default alternative to QMessageBox

    So I tried this short piece of code but I won't quit.
    The window with my button is displayed ans sits there forever.

    Qt Code:
    1. #include "mainwindow.h"
    2. #include <QTimer>
    3.  
    4. MainWindow::MainWindow() : QMainWindow()
    5. {
    6.  
    7. //Make a dialog with a timer and
    8. //connect its timeout() signal to dialogs accept() slot.
    9.  
    10. pbClose = new QPushButton( this );
    11. pbClose->resize( QSize( 10, 10 ) );
    12. QTimer *timer = new QTimer(this);
    13. connect(timer, SIGNAL(timeout()), this, SLOT(quit()));
    14. connect( pbClose, SIGNAL( timeout() ), this, SLOT( quit() ) );
    15. timer->start(100);
    16.  
    17. }
    To copy to clipboard, switch view to plain text mode 
    Connecting to accept() fails too.

    Qt Code:
    1. QTimer::singleShot(200, this, SLOT(quit()));
    To copy to clipboard, switch view to plain text mode 
    is no better
    Last edited by incapacitant; 22nd May 2006 at 10:41.

  5. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: alternative to QMessageBox

    Use QDialog. QMainWindow does not have a slot quit().
    J-P Nurmi

  6. The following user says thank you to jpn for this useful post:

    incapacitant (22nd May 2006)

  7. #5
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    106

    Default alternative to QMessageBox

    My knowledge does not goes as far as subclassing for the time being.
    Where can I read something about subclassing Accelerated C++ does not even have it in the index !

    In any case my application has otherthings to do after the timeout.
    So I rewrote it as this, and it works :

    Qt Code:
    1. #include "mainwindow.h"
    2. #include <QTimer>
    3.  
    4. MainWindow::MainWindow() : QMainWindow()
    5. {
    6.  
    7. //Make a dialog with a timer and
    8. //connect its timeout() signal to dialogs accept() slot.
    9.  
    10. pbClose = new QPushButton( this );
    11. pbClose->resize( QSize( 10, 10 ) );
    12. QTimer *timer = new QTimer(this);
    13. QTimer::singleShot(2000, this, SLOT(stop()));
    14. timer->start();
    15.  
    16. }
    17.  
    18. void MainWindow::stop()
    19. {
    20. close();
    21. }
    To copy to clipboard, switch view to plain text mode 

  8. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: alternative to QMessageBox

    MainWindow is a subclass of QMainWindow, so you are subclassing Subclassing is a process of implementing a class which inherits some other classes.

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

    incapacitant (22nd May 2006)

  10. #7
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    106

    Default alternative to QMessageBox

    I'm trying to integrate to the successfull short code above in my application as :

    Qt Code:
    1. sendMsg sendMsg_dlg( this );
    2. if ( sendMsg_dlg.exec() )
    3. {
    4. QTimer *timer = new QTimer(this);
    5. QTimer::singleShot(2000, this, SLOT(closeSendMsg()));
    6. timer->start();
    7. }
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. void ApplicationWindow::closeSendMsg()
    2. {
    3. close();
    4. finaliseEnvoi();
    5. }
    To copy to clipboard, switch view to plain text mode 

    The sendMsg dialog is displayed but the closeSendMsg slot is not called and the dialog sits there.

    I was told : Make a dialog with a timer and connect its timeout() signal to dialogs accept() slot.

    I must be doing something wrong but despite several tries cannot fix it.

  11. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: alternative to QMessageBox

    Try something like this:

    Qt Code:
    1. class WaitDialog : public QDialog {
    2. public:
    3. WaitDialog(uint interval, QWidget *p=0) : QDialog(p){
    4. QVBoxLayout *l = new QVBoxLayout(this);
    5. QLabel *lab = new QLabel("Please wait");
    6. l->addWidget(lab);
    7. setLayout(l);
    8. timer.setSingleShot(true);
    9. timer.setInterval(interval);
    10. connect(&timer, SIGNAL(timeout()), this, SLOT(accept()));
    11. }
    12. void exec(){
    13. timer.start();
    14. QDialog::exec();
    15. }
    16. private:
    17. QTimer timer;
    18. };
    To copy to clipboard, switch view to plain text mode 

  12. The following user says thank you to wysota for this useful post:

    incapacitant (22nd May 2006)

  13. #9
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    106

    Default alternative to QMessageBox

    Ok, I am thick, I can't even call it from my code.

    Qt Code:
    1. sendMsg sendMsg_dlg( this );
    2. if ( sendMsg_dlg.exec() )
    3. {
    4. WaitDialog::WaitDialog(200,sendMsg);
    5. }
    To copy to clipboard, switch view to plain text mode 
    This does not compile:
    447 C:\root\dev\Qt\sms data\sms\menu.cpp expected primary-expression before '(' token
    447 C:\root\dev\Qt\sms data\sms\menu.cpp expected primary-expression before ')' token

    All I am doing is trying random combination, without really understanding all to call your class. Hopeless

    But elsewhere I managed to set an icon to my application without asking on the forum. lol
    Last edited by incapacitant; 22nd May 2006 at 18:38.

  14. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: alternative to QMessageBox

    You should learn instead of shooting random. I won't give you the exact code, let it be your homework for today to think and learn how to do it. I'll give you a hint though. You use this dialog like any other dialog. The only difference is the time to wait parameter which you have to use while constructing the dialog.

  15. The following user says thank you to wysota for this useful post:

    incapacitant (22nd May 2006)

  16. #11
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    106

    Default alternative to QMessageBox

    ok, I already understood the way you think about all this and I think it is 100% sane.
    I will search and try... thanks

Similar Threads

  1. QMessageBox missing icon
    By zanth in forum Qt Programming
    Replies: 3
    Last Post: 8th July 2010, 21:20
  2. QMessageBox buttons appearance
    By yartov in forum Qt Programming
    Replies: 6
    Last Post: 26th June 2008, 01:36
  3. Display row Number in QMessageBox
    By arunvv in forum Newbie
    Replies: 6
    Last Post: 1st May 2008, 23:24
  4. Re: Help on QMessageBox
    By arunvv in forum Newbie
    Replies: 2
    Last Post: 25th March 2008, 23: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.