Results 1 to 13 of 13

Thread: QHBoxLayout and QMessageBox error

  1. #1
    Join Date
    Jan 2007
    Posts
    95
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    5

    Default QHBoxLayout and QMessageBox error

    I have programmed a class like this:

    Qt Code:
    1. class WindowsTextEditor : public QHBoxLayout
    To copy to clipboard, switch view to plain text mode 

    and with a constructor, and other functions that i need. This class works fine, but i need to send a message from this class to ask if you want to save a file or not. I have used this (in the constructor or into other functions):

    Qt Code:
    1. int ret=QMessageBox::question(this,"Programm",
    2. "Do you want to save...?",
    3. QMessageBox::Yes | QMessageBox::Default,
    4. QMessageBox::No | QMessageBox::Escape);
    To copy to clipboard, switch view to plain text mode 

    But i get this error:

    error C2665: 'QMessageBox::question' : none of the 4 overloads can convert parameter...

    How can i call QMessageBox from this class (WindowsTextEditor : public QHBoxLayout)?

    Thanks

  2. #2
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11
    Thanks
    8
    Thanked 14 Times in 14 Posts

    Default Re: QHBoxLayout and QMessageBox error

    Quote Originally Posted by zorro68 View Post
    I have programmed a class like this:

    Qt Code:
    1. class WindowsTextEditor : public QHBoxLayout
    To copy to clipboard, switch view to plain text mode 

    and with a constructor, and other functions that i need. This class works fine, but i need to send a message from this class to ask if you want to save a file or not. I have used this (in the constructor or into other functions):

    Qt Code:
    1. int ret=QMessageBox::question(this,"Programm",
    2. "Do you want to save...?",
    3. QMessageBox::Yes | QMessageBox::Default,
    4. QMessageBox::No | QMessageBox::Escape);
    To copy to clipboard, switch view to plain text mode 

    But i get this error:

    error C2665: 'QMessageBox::question' : none of the 4 overloads can convert parameter...

    How can i call QMessageBox from this class (WindowsTextEditor : public QHBoxLayout)?

    Thanks
    Qt Code:
    1. #include <QtGui>
    2. class WindowsTextEditor : public QHBoxLayout
    3. {
    4. public:
    5. WindowsTextEditor(QWidget *parent=0):QHBoxLayout(parent){
    6.  
    7. int ret=QMessageBox::question(0,"Programm",
    8.  
    9. "Do you want to save...?",
    10.  
    11. QMessageBox::Yes | QMessageBox::Default,
    12.  
    13. QMessageBox::No | QMessageBox::Escape);
    14. }
    15. };
    16.  
    17. int main (int argc, char **argv)
    18. {
    19.  
    20. QApplication app(argc,argv);
    21. WindowsTextEditor w;
    22. QWidget mainWin;
    23. QPushButton *pb1=new QPushButton("One");
    24. QPushButton *pb2=new QPushButton("Two") ;
    25. w.addWidget(pb1);
    26. w.addWidget(pb2);
    27. mainWin.setLayout(&w);
    28. mainWin.show();
    29. return app.exec();
    30. }
    To copy to clipboard, switch view to plain text mode 
    Hope it helps!
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  3. #3
    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: QHBoxLayout and QMessageBox error

    Wouldn't it be more natural if WindowsTextEditor inherited one of available widget classes instead of a layout? It can always install a layout on itself but inheriting from a layout is weird since it clearly is a widget. Which of layout features are you extending with that subclass?
    J-P Nurmi

  4. #4
    Join Date
    Jan 2007
    Posts
    95
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    5

    Default Re: QHBoxLayout and QMessageBox error

    ashukla:
    I try what you say and get the same error.

    jpn:
    You are right. I think this is a qwidget, but if i change the QHBoxlayout to a Qwidget, all widget inside the qwidget position wherever the want, and don't put where i want. So I try with a QSplitter but I dont want to resize the objects inside (a QDockWidget and a QTabWidget, and this with a QTextBox and two buttons). With a qwidget or a qsplitter i can only see a big button that expand in all windows.......
    I dont know why.

    Sorry for my English.

    Thanks

  5. #5
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11
    Thanks
    8
    Thanked 14 Times in 14 Posts

    Default Re: QHBoxLayout and QMessageBox error

    ashukla:
    I try what you say and get the same error.
    Dear Zorro68!
    It's work fine for me. Can you restate your problem with code.
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  6. #6
    Join Date
    Nov 2007
    Posts
    89
    Qt products
    Qt4
    Platforms
    Windows
    Thanked 21 Times in 18 Posts

    Default Re: QHBoxLayout and QMessageBox error

    Quote Originally Posted by zorro68 View Post
    You are right. I think this is a qwidget, but if i change the QHBoxlayout to a Qwidget, all widget inside the qwidget position wherever the want, and don't put where i want. So I try with a QSplitter but I dont want to resize the objects inside (a QDockWidget and a QTabWidget, and this with a QTextBox and two buttons). With a qwidget or a qsplitter i can only see a big button that expand in all windows.......
    I dont know why.
    You shouldn't add widgets to your widget directly. You should create a layout, add all widgets to layout, then set the layout to your widget.

  7. #7
    Join Date
    Jan 2007
    Posts
    95
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    5

    Default Re: QHBoxLayout and QMessageBox error

    bender86:
    I know, and i dont do this.

    ashukla:
    I send you a reduced example of my programm.


    Thanks
    Attached Files Attached Files

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

    Default Re: QHBoxLayout and QMessageBox error

    So where exactly is the problem?

  9. #9
    Join Date
    Jan 2007
    Posts
    95
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    5

    Default Re: QHBoxLayout and QMessageBox error

    If you compile and run the programm i have send, you notice that main windows shows a big BTNnew button only in the area where must shows all widgets (tabwidget, two buttons,....) and this layout dont resize with main windows.

    I use QT 4.3.1 for windows...(maybe is this the problem?)
    Attached Images Attached Images

  10. #10
    Join Date
    Jan 2007
    Posts
    95
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    5

    Default Re: QHBoxLayout and QMessageBox error

    Anybody knows who is my problem with my programm?

    Thanks

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

    Default Re: QHBoxLayout and QMessageBox error

    Actually I can't compile your program. qmake complains for lots of missing files (case sensivity thing mostly I guess).

    By looking at your code I see some problems. First of all you are placing a dock widget inside a layout, which does not make much sense as it should be managed by the main window and placed in proper places inside the window's layout and not yours. And second of all it would be *much* easier and simpler (to implement and debug) if you used Qt Designer to build your GUI. Currently I'm getting lost after some tenth or so widget is created. I suggest you switch to using Designer and the problem will probably solve itself.

  12. #12
    Join Date
    Jan 2007
    Posts
    95
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    5

    Default Re: QHBoxLayout and QMessageBox error

    First of all you are placing a dock widget inside a layout, which does not make much sense as it should be managed by the main window and placed in proper places inside the window's layout and not yours
    The reason of doing this is because I want this widget appear and disappear pushing a button, thats why i made the windowstextEditor class with functions setvisible and setenabled.

    And second of all it would be *much* easier and simpler (to implement and debug) if you used Qt Designer to build your GUI. Currently I'm getting lost after some tenth or so widget is created. I suggest you switch to using Designer and the problem will probably solve itself.
    I don't like to use QTDesigner. You loose the control of widget.... (my oppinion).

    Thaks.

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

    Default Re: QHBoxLayout and QMessageBox error

    Quote Originally Posted by zorro68 View Post
    The reason of doing this is because I want this widget appear and disappear pushing a button, thats why i made the windowstextEditor class with functions setvisible and setenabled.
    I don't see a reason for using a dock widget for that. You can do it with any widget.


    I don't like to use QTDesigner. You loose the control of widget.... (my oppinion).
    You don't loose anything as you can implement anything you want when making a widget for the form. And currently you have non-working code. I'd rather have less control over a widget (assuming that was the case, which is not) than total control over code that does not work.

    By looking at your code I don't see anything that can't be done with Designer.

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.