Page 1 of 2 12 LastLast
Results 1 to 20 of 21

Thread: alternative to QMessageBox

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

    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,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: 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
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    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
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    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
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    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,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: 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
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    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,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: 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
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    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,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: 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
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    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

  17. #12
    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: alternative to QMessageBox

    You don't have to search. Just look at the code you already have and *think*.

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

    incapacitant (22nd May 2006)

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

    Default alternative to QMessageBox

    You say that I should consider this dialog as any other one, so I think I found out how to instantiate it as it compiles :

    Qt Code:
    1. waitDialog_dlg = new WaitDialog::WaitDialog(200, this);
    To copy to clipboard, switch view to plain text mode 

    The trouble now is to invoke the dialog :
    Qt Code:
    1. if ( waitDialog_dlg.exec() )
    2. {
    3. }
    To copy to clipboard, switch view to plain text mode 

    compile error :
    445 C:\root\dev\Qt\sms data\sms\menu.cpp `exec' has not been declared

    With :
    Qt Code:
    1. if ( WaitDialog::waitDialog_dlg.exec() )
    2. {
    3. }
    To copy to clipboard, switch view to plain text mode 

    compile error :
    445 C:\root\dev\Qt\sms data\sms\menu.cpp `waitDialog_dlg' is not a member of `WaitDialog'

    waitDialog_dlg is a member of my ApplicationWindow class like my other dialogs.
    Qt Code:
    1. class ApplicationWindow: public QMainWindow
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. ApplicationWindow();
    7. ~ApplicationWindow();
    8.  
    9. // dialog
    10. Destinataires *Destinataires_dlg;
    11. Archives *Archives_dlg;
    12. sendMsg *sendMsg_dlg;
    13. WaitDialog *waitDialog_dlg;
    To copy to clipboard, switch view to plain text mode 


    I tried to declare the dialog in the WaitDialog class but things get worse...

  20. #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: alternative to QMessageBox

    Oh man... I hate to do this, but I suggest you learn some C++ before trying with Qt.

    Check out our links section, especially the one with C++ links. You should start with Thinking in C++ and Correct C++ Tutorial.

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

    incapacitant (23rd May 2006)

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

    Default alternative to QMessageBox

    ok, I will read. Thanks.

  23. #16
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: alternative to QMessageBox

    Qt Code:
    1. waitDialog_dlg = new WaitDialog(200, this);
    To copy to clipboard, switch view to plain text mode 
    a life without programming is like an empty bottle

  24. The following user says thank you to zlatko for this useful post:

    incapacitant (23rd May 2006)

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

    Default alternative to QMessageBox

    zlatko:
    Thanks I have done that bit to instantiate the dialog.
    The trouble remains how to call, display and start the dialog and its timer

  26. #18
    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: alternative to QMessageBox

    Please learn it yourself.

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

    Default alternative to QMessageBox

    I knew zlatko was going to get trouble. Yes, master. I have downloaded the books.

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

    Default alternative to QMessageBox

    wysota: It is true that I have to learn, and I thank you for your attitude.

    For info, your class had a bug, the correct code is :
    Qt Code:
    1. class WaitDialog : public QDialog {
    2. public:
    3. WaitDialog(uint interval, QWidget *p=0) : QDialog(p)
    4. {
    5. QVBoxLayout *l = new QVBoxLayout(this);
    6. QLabel *lab = new QLabel("Please wait");
    7. l->addWidget(lab);
    8. setLayout(l);
    9. timer.setSingleShot(true);
    10. timer.setInterval(interval);
    11. connect(&timer, SIGNAL(timeout()), this, SLOT(accept()));
    12. }
    13.  
    14. int exec() // rather than void
    15. {
    16. timer.start();
    17. return QDialog::exec(); // needed return
    18. }
    19.  
    20. private:
    21. QTimer timer;
    22. };
    To copy to clipboard, switch view to plain text mode 

    Then to call it :
    Qt Code:
    1. WaitDialog waitDialog_dlg( 2000, this );
    2. if ( waitDialog_dlg.exec() )
    3. {
    4. }
    To copy to clipboard, switch view to plain text mode 

    I learn slowly, but I am stubborn and I will get there.

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.