Re: Extend the ui_xxx.h file
Quote:
Originally Posted by
dosto.walla
2. I would like to extend that ui_xxx.h file that will be auto generated by the Qt and add more features to that .
Don't change the ui_xxx.h file, because it will be overwritten when you change your .ui file.
See http://doc.trolltech.com/4.4/designe...component.html
Quote:
Originally Posted by
dosto.walla
I put the GUI items using Qt designer but could not figure out the way of incorporating the paint interface to that.
That "paint interface" is a custom widget. You can use the widget promotion mechanism or write your own widget plugin.
See http://doc.trolltech.com/4.4/designe...moting-widgets
Re: Extend the ui_xxx.h file
Thanks for the link
Accordingly i have been trying the "Calculator Form Example" found in
designer/calculatorform/calculatorform.h
while compiling i ended up with the following error:
CalculatorForm.cpp: In constructor ‘CalculatorForm::CalculatorForm(QWidget*)â⠂¬â„¢:
CalculatorForm.cpp:8: error: no matching function for call to ‘Ui::CalculatorForm::setupUi(CalculatorForm* const)’
ui_calculatorform.h:36: note: candidates are: void Ui_CalculatorForm::setupUi(QDialog*)
make: *** [CalculatorForm.o] Error 1
It is virtually copy paste of the tutorial
Could you please point out what am i missing in the process?
Regards
Sajjad
Re: Extend the ui_xxx.h file
Does your CalculatorForm inherit QDialog?
Re: Extend the ui_xxx.h file
no it does not....
That is the following format given in the Qt's official tutorial....
*****************************'
#ifndef CALCULATORFORM_H
#define CALCULATORFORM_H
#include "ui_calculatorform.h"
class CalculatorForm : public QWidget
{
Q_OBJECT
public:
CalculatorForm(QWidget *parent = 0);
private slots:
void on_inputSpinBox1_valueChanged(int value);
void on_inputSpinBox2_valueChanged(int value);
private:
Ui::CalculatorForm ui;
};
#endif
*****************************************
According to the error information the class should inherit QDialog not QWidget. But Should there be a problem because of that?
QDialog is anyway a subclass of the QWidget.
Regards
Sajjad
Re: Extend the ui_xxx.h file
Quote:
Originally Posted by
dosto.walla
According to the error information the class should inherit QDialog not QWidget. But Should there be a problem because of that?
You have created the .ui file using a dialog template. Therefore your widget has to be a dialog.
Re: Extend the ui_xxx.h file
I have created the form widget(not dialog) using the Qt Designer and then add all the necessary labels and spin boxes to interact with them.
Then i executed the qmake -project to create the header file from the .ui file. And inside the header file i can see that there is a function created that expects a (setupUi(QDialog*)) QDialog as a parameter.
To use that component using single inheritance approach i created a class CalculatorForm which is the subclass of QWidget and there is where i get the error saying:
Not a good idea though paste such a chunk of code in the forum..........
***********************CalculatorForm.h*********** **********
Code:
#ifndef CALCULATORFORM_H
#define CALCULATORFORM_H
#include "ui_calculatorform.h"
class CalculatorForm
: public QWidget {
Q_OBJECT
public:
CalculatorForm
(QWidget *parent
= 0);
private slots:
void on_inputSpinBox1_valueChanged(int value);
void on_inputSpinBox2_valueChanged(int value);
private:
Ui::CalculatorForm ui;
};
#endif
***********************CalculatorForm.h*********** **********
***********************CalculatorForm.cpp********* ************
Code:
#include <QtGui>
#include "CalculatorForm.h"
CalculatorForm
::CalculatorForm(QWidget *parent
) {
ui.setupUi(this);
}
void CalculatorForm::on_inputSpinBox1_valueChanged(int value)
{
ui.
outputWidget->setText
(QString::number(value
+ ui.
inputSpinBox2->value
()));
}
void CalculatorForm::on_inputSpinBox2_valueChanged(int value)
{
ui.
outputWidget->setText
(QString::number(value
+ ui.
inputSpinBox1->value
()));
}
***********************CalculatorForm.cpp********* ************
Quote:
sajjad@sajjad:~/QT/calculatorform$ make
g++ -c -pipe -fpermissive -g -Wall -W -D_REENTRANT -DQT_SHARED -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I. -o CalculatorForm.o CalculatorForm.cpp
In file included from CalculatorForm.cpp:3:
CalculatorForm.h:18: error: ‘CalculatorForm’ in namespace ‘Ui’ does not name a type
CalculatorForm.cpp: In constructor ‘CalculatorForm::CalculatorForm(QWidget*)â⠂¬â„¢:
CalculatorForm.cpp:8: error: ‘ui’ was not declared in this scope
CalculatorForm.cpp: In member function ‘void CalculatorForm::on_inputSpinBox1_valueChanged(int) ’:
CalculatorForm.cpp:13: error: ‘ui’ was not declared in this scope
CalculatorForm.cpp: In member function ‘void CalculatorForm::on_inputSpinBox2_valueChanged(int) ’:
CalculatorForm.cpp:18: error: ‘ui’ was not declared in this scope
make: *** [CalculatorForm.o] Error 1
I did not understand the error.
Really need some light into that issue.
Regards
Sajjad
Re: Extend the ui_xxx.h file
Quote:
Originally Posted by
dosto.walla
And inside the header file i can see that there is a function created that expects a (setupUi(QDialog*)) QDialog as a parameter.
That's because you have used a dialog template in Qt Designer.
What is the name of your .ui file and what is the objectName of your form? Also post your .pro file.
Re: Extend the ui_xxx.h file
The name of the ui file is calculatorform.ui and the contents of the .pro file is as follows:
*****************
################################################## ####################
# Automatically generated by qmake (2.01a) Thu Sep 4 12:38:54 2008
################################################## ####################
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
# Input
HEADERS += CalculatorForm.h
FORMS += calculatorform.ui
SOURCES += CalculatorForm.cpp main.cpp
*****************
Re: Extend the ui_xxx.h file
Is your form named "CalculatorForm" (check the objectName property)?
Re: Extend the ui_xxx.h file
the .ui file is saved as calculatorform.ui and the objectName property is set to the value Form
Regards
Sajjad
Re: Extend the ui_xxx.h file
Quote:
Originally Posted by
dosto.walla
the objectName property is set to the value Form
In that case you have to use Ui::Form not Ui::CalculatorForm.
Re: Extend the ui_xxx.h file
Thanks Jacek,
Extending a component through the use of inheritance is functional.
Now i have another issue regarding layout designing within Qt designer.
I created a form widget and created some components(button, combo boxes)
within the form and grouped them together in a grid layout.
Then i inherit that class generated by qt compiler and incorporated a RenderArea class where i can draw different primitives.
And creating another layout of grid layout type and then adding the render area as widget and the previous grid layout from the super class . The code snippet is as follows:
***************************''
//create the layout
QGridLayout *mainLayout = new QGridLayout;
//add the render area and the items that have been
//created with Qt Designer
mainLayout->addWidget(renderArea,0,0);
mainLayout->addLayout(ui.gridLayout,1,0);
setLayout(mainLayout);
*****************************''
The code compiled fine. But while running having the following error:
QLayout::addChildLayout: layout "gridLayout" already has a parent
Segmentation fault
Any Idea?
Regards
Sajjad
Re: Extend the ui_xxx.h file
If you want to add a widget to the layout created with Qt Designer, it is easier to use the widget promotion mechanism.
http://doc.trolltech.com/4.4/designe...moting-widgets
1 Attachment(s)
Re: Extend the ui_xxx.h file
Hello jacek,
I have gone through the material that you have sent with the link.
"To add a placeholder, select an object of a suitable base class and choose Promote to ... from the form's context menu. After entering the class name and header file in the lower part of the dialog, choose Add. The placeholder class will now appear along with the base class in the upper list. Click the Promote button to accept this choice."
I did not understand exactly how do i do that. If you please take a look at the attached png file, you will see that a form with widgets already in the layout.
What i want to do is :
1. Create a main layout and add the layout that you see in the form to the main layout.
2. Create the RenderArea that is the subclass of the QWidget and add that to the main layout.
So in that case which one is the place-holder that i should promote to?
While designing the form i have the form itself and the other widgets set in a grid layout , what is not there is the RenderArea and it is the subclass of QWidget and how do i choose the place-holder for the RenderArea and who would be the place-holder?
Regards
Sajjad
Re: Extend the ui_xxx.h file
Quote:
Originally Posted by
dosto.walla
So in that case which one is the place-holder that i should promote to?
If your custom class is derived from QWidget, then add a QWidget to your form and promote it.
Re: Extend the ui_xxx.h file
Thanks jacek,
Drag a QWidget within the Qt Designer and promoted it to the custom class that i have made.
Now i have almost the same error:
QLayout::addChildLayout: layout "gridLayout" already has a parent
Segmentation fault
Another forum said something related to that
"If you want to create a sub-layout (i.e. you want to add it to another
layout), then you have to create it WITHOUT a parent. Just use the
constructor of QLayout without a parent.
Only add a parent (namely the top widget) for a top level layout (i.e. the
main layout of a widget).
"
How do i do that from within the Qt Designer?
In my case the gridLayout is the sub layout. and i have to instantiate that without a parent.
Regards
Sajjad
Re: Extend the ui_xxx.h file
Quote:
Originally Posted by
dosto.walla
QLayout::addChildLayout: layout "gridLayout" already has a parent
The problem is that you try to add a layout to a form that already has a layout. Qt doesn't like this.
Quote:
Originally Posted by
dosto.walla
How do i do that from within the Qt Designer?
Either drag a layout from the toolbox just as if it was a widget or select few widgets and click the "Lay out in ..." action (you should see a red rectangle around those widgets).
5 Attachment(s)
Re: Extend the ui_xxx.h file
Hello jacek,
i am still having the same error. So i am attaching the related files.
I hope that you can make some time out of your busy schedule.
Regards
Sajjad
1 Attachment(s)
Re: Extend the ui_xxx.h file
Hello jacek,
I have attached some screen-shots of the things you have recommended to do to avoid the error:
The image that is attached first shows the following:
1. All the toolbars that are arranged in a grid layout.
2. The rectangle box beside that is a QWidget that i have dragged into the form.
The second image shows how i promoted the custom class RenderArea.h to one of the place-holders(QWidget)
The i compiled them ,but while running i have the runtime error as follows:
QLayout::addChildLayout: layout "gridLayout" already has a parent
Segmentation fault
It says that the gridLayout already has a parent
i followed you suggestion
"Either drag a layout from the toolbox just as if it was a widget or select few widgets and click the "Lay out in ..." action (you should see a red rectangle around those widgets)."
I followed the one in the bold mark. And you can see that in the attached images as well.
Regards
Sajjad