PDA

View Full Version : QHBoxLayout and QMessageBox error



zorro68
2nd February 2008, 01:43
I have programmed a class like this:



class WindowsTextEditor : public QHBoxLayout


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):



int ret=QMessageBox::question(this,"Programm",
"Do you want to save...?",
QMessageBox::Yes | QMessageBox::Default,
QMessageBox::No | QMessageBox::Escape);


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)?:confused::confused::confused:

Thanks

ashukla
2nd February 2008, 05:24
I have programmed a class like this:



class WindowsTextEditor : public QHBoxLayout


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):



int ret=QMessageBox::question(this,"Programm",
"Do you want to save...?",
QMessageBox::Yes | QMessageBox::Default,
QMessageBox::No | QMessageBox::Escape);


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)?:confused::confused::confused:

Thanks

#include <QtGui>
class WindowsTextEditor : public QHBoxLayout
{
public:
WindowsTextEditor(QWidget *parent=0):QHBoxLayout(parent){

int ret=QMessageBox::question(0,"Programm",

"Do you want to save...?",

QMessageBox::Yes | QMessageBox::Default,

QMessageBox::No | QMessageBox::Escape);
}
};

int main (int argc, char **argv)
{

QApplication app(argc,argv);
WindowsTextEditor w;
QWidget mainWin;
QPushButton *pb1=new QPushButton("One");
QPushButton *pb2=new QPushButton("Two") ;
w.addWidget(pb1);
w.addWidget(pb2);
mainWin.setLayout(&w);
mainWin.show();
return app.exec();
}
Hope it helps!

jpn
2nd February 2008, 05:46
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?

zorro68
2nd February 2008, 21:05
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.......:confused:
I dont know why.

Sorry for my English.

Thanks

ashukla
3rd February 2008, 04:40
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.

bender86
3rd February 2008, 08:56
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.......:confused:
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.

zorro68
3rd February 2008, 11:55
bender86:
I know, and i dont do this.

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


Thanks

wysota
3rd February 2008, 12:04
So where exactly is the problem?

zorro68
3rd February 2008, 13:22
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?)

zorro68
6th February 2008, 22:00
Anybody knows who is my problem with my programm?

Thanks

wysota
6th February 2008, 22:57
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.

zorro68
7th February 2008, 10:26
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.

wysota
7th February 2008, 10:57
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.