PDA

View Full Version : What does this command mean?



mr.dct
19th March 2010, 01:40
Hello everyone, I'm a newbie. Im learning QT language with the "C++ GUI programming with Qt4". I don't really know about the following command:


class SortDialog : public QDialog, public Ui::SortDialog

Anyone tell me what does it mean. Thanks alot.
A SortDialog dialog had been designed before.

aamer4yu
19th March 2010, 04:52
This is not about Qt... its about C++

class SortDialog : public QDialog, public Ui::SortDialog
it says SortDialog is a class which inherits QDialog class and Ui::SortDialog class.

Ui is a namespace, and Ui::SortDialog is the class in the namespace Ui.
Basically this class must be designed in designer and then code created with uic.

Have you designed it ? If yes, would suggest to change design,,, because inheriting from two dialogs doesnt make sense..does it ?
You could very well had Ui::SortDialog inherited from QDialog, and SortDialog from Ui::SortDialog.

mr.dct
19th March 2010, 08:11
Thanks for your reply.
By your meaning, I should have Ui::SortDialog inherited from QDialog. So how can I have it.
Cause I designed the Dialog with the Qt Designer and then qmake will create the header file automatically.
Can I hand-code this file or It will automatically inherited the QDialog class.
P/S: I'm not good at English. So if I make some typing error, grammar error, etc... pls let me know.

aamer4yu
19th March 2010, 09:35
You can do something like in your header file -

#include "ui_mainWidget.h"
class MainWindow : public QMainWindow
{
Q_OBJECT

private:
Ui::MainWindow ui; // Ui::Mainwindow is the class name you gave to the widget in designer. check ui_****.h file when uic is run over .ui file.
public:
MainWindow();
};

and in cpp -


MainWindow::MainWindow()
{
ui.setupUi(this);
}

Also search examples in Qt Demos... I guess you will find some example how they have used .ui file

wysota
19th March 2010, 09:38
Have you designed it ? If yes, would suggest to change design,,, because inheriting from two dialogs doesnt make sense..does it ?
Ui::SortDialog is not a dialog, it's a Designer form class. The construct quoted is perfectly valid

You could very well had Ui::SortDialog inherited from QDialog, and SortDialog from Ui::SortDialog.
No, this wouldn't work.

aamer4yu
19th March 2010, 10:12
No, this wouldn't work.
Yea, not exactly the statement. I guess i wrote in a hurry...
What I meant was like the example I posted, instead of inheriting from 2 classes, one can inherit from one, and setup the ui from the uic generated code.

mr.dct
20th March 2010, 03:15
Hi aamer4yu. I tried to do like you sad but it return this:


#include <QMainWindow>
#include "ui_ShapeChangingDialog.h"

class ShapeChangingDialog : public QMainWindow
{
Q_OBJECT
public:
ShapeChangingDialog(QWidget *parent = 0);
void setColumnRange(QChar first, QChar last);
private:
Ui::ShapeChangingDialog ui;
};


ShapeChangingDialog.h:14: error: ‘ShapeChangingDialog’ in namespace ‘Ui’ does not name a type

Can you help me fix this. Thanks !

aamer4yu
20th March 2010, 05:52
Whats the object name you have given to the widget in your .ui file ? The class type and object name must match.
For example for above code, in designer you will need to create a QMainWindow, and the object name must be ShapeChangingDialog
just see some example and play with them.

Lykurg
20th March 2010, 06:04
Hi,

since you don't have basic knowledge of C++, I would advice you first to learn the basics of C++. Till then stay with the code Qt creator designs for you because it works and in for normal use cases it is perfect.
If you understand to a later time what all means (and aamer4yu has explained it for you in his first reply) then you can change things. But right now it don't make sense just to add somewhere "Dialog" without understanding what is does.

Lykurg

mr.dct
20th March 2010, 07:55
Actually I had learn C++ 2 years ago. On that day, I work with VC++ to make an Image Compressing Application for my project. Till now, I have ever work with with it again. Hence most of them go out of my memory. Now in my new project, I must work with Asterisk and Application in Redhat, so I learn Qt. Your advice is absolutely right. At the beginning I though like you sad, but I feel it will take more time than to learn both of them together. Maybe I must review C++ again. Thanks.
@aamer4yu: Actually, I designed an Dialog named ShapeChangingDialog before, then I hand-code for it like you sad but I created a subclass of QDialog, not QMainWindow. It still don't work. The qmake had automatically create a ui_ShapeChangingDialog.h header file so it means the name of my dialog is absolutely match with the class.

ChrisW67
22nd March 2010, 22:33
The qmake had automatically create a ui_ShapeChangingDialog.h header file so it means the name of my dialog is absolutely match with the class.
Qt qmake will do this if there is a Designer form file listed in the the pro file FORMS variable. If you want to hand code your forms than don't use Designer or the FORMS variable.

azharbk
23rd March 2010, 07:45
Hi,

I think your are referring to the example in book "C++ GUI Programming with Qt 4, Second Edition" Creating Dialogs - Shape-Changing Dialogs. Its mentioned in the book "The generated ui_gotocelldialog.h file contains the definition of the Ui::GoToCellDialog class, which is a C++ equivalent of the gotocelldialog.ui file. The class declares member variables that store the form's child widgets and layouts, and a setupUi() function that initializes the form."

Thus, bascially the line "class SortDialog : public QDialog, public Ui::SortDialog" means you are inheriting both from "QDialog" (provides the Dialog functionality to your object) and "Ui::SortDialog" (provides the setup of your 'dialog' object).
Therefore, in "sortdialog.cpp", you can see in the contructor of "SortDialog",



SortDialog::SortDialog(QWidget *parent)
: QDialog(parent)
{
setupUi(this); // This call is made to initialze and setup the dialog


and you can see in "ui_gotocelldialog.h", the definition of "setupUi(QDialog *SortDialog)". In this, to the dialog object, various objects are added viz. labels, buttons, etc. Also, layouts for proper layout of GUI objects added, etc.

If you want to hand-code the setup of your dialog says adding various GUI elements, adding proper layout, etc. then you don't need the "Ui::SortDialog" (You can do this in the constructor of your object itself). This is created if your using the RAD tool "Qt Designer" which is a GUI tool to create UI forms.

Hope this help.

Regards,
Azhar

mr.dct
23rd March 2010, 09:23
Thanks to Azhar, I've review the ui_ShapeChangingDialog.h file and solve my problem. The class that Ui tool creates is shapeChangingDialog not ShapeChangingDialog. I make a mistake when typing the ObjectName. I also understand deeper about many other thing when reading this file. Thanks everyone.

mr.dct
23rd March 2010, 09:41
I have another problem but about Qt Desinger. When I use the QGroupBox, it has no border like in that example. I tried to set "
border:1px solid rgb(x,x,x);" but it return a border with sqare edge, not curve edge like in the book. I though must use border-radius parameter but it didn't work too. Someone help me to set the right command, and make it the default style when creating a groupbox ??? Thanks.

wysota
23rd March 2010, 09:52
The example in the book probably uses a different widget style than your system. You can preview the form in Designer in different styles by choosing an appropriate entry from the "Form/Preview in" menu.