QHBoxLayout and QMessageBox error
I have programmed a class like this:
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):
Code:
"Do you want to save...?",
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
Re: QHBoxLayout and QMessageBox error
Quote:
Originally Posted by
zorro68
I have programmed a class like this:
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):
Code:
"Do you want to save...?",
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
Code:
#include <QtGui>
{
public:
"Do you want to save...?",
}
};
int main (int argc, char **argv)
{
WindowsTextEditor w;
w.addWidget(pb1);
w.addWidget(pb2);
mainWin.setLayout(&w);
mainWin.show();
return app.exec();
}
Hope it helps!
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?
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.......:confused:
I dont know why.
Sorry for my English.
Thanks
Re: QHBoxLayout and QMessageBox error
Quote:
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.
Re: QHBoxLayout and QMessageBox error
Quote:
Originally Posted by
zorro68
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.
1 Attachment(s)
Re: QHBoxLayout and QMessageBox error
bender86:
I know, and i dont do this.
ashukla:
I send you a reduced example of my programm.
Thanks
Re: QHBoxLayout and QMessageBox error
So where exactly is the problem?
1 Attachment(s)
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?)
Re: QHBoxLayout and QMessageBox error
Anybody knows who is my problem with my programm?
Thanks
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.
Re: QHBoxLayout and QMessageBox error
Quote:
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.
Quote:
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.
Re: QHBoxLayout and QMessageBox error
Quote:
Originally Posted by
zorro68
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.
Quote:
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.