Page 1 of 2 12 LastLast
Results 1 to 20 of 21

Thread: Extend the ui_xxx.h file

  1. #1
    Join Date
    Sep 2008
    Posts
    21
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Extend the ui_xxx.h file

    Hello Forum,


    Quite new to the Qt community.

    I would like to do the following issues.

    1. With Qt Designer i have designed a form with several GUI buttons and combo
    boxes and set them all together in a Grid layout.

    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 .


    Just going through the basic examples that come along with the Qt installations and trying to re-implement the "Basic Drawing Example" using Qt
    Designer.

    If you look at that example you will see that there is a paint interface and then down to that paint interface there are several GUI items to interact with them. I put the GUI items using Qt designer but could not figure out the way of incorporating the paint interface to that.


    Is Subclassing one way of doing that ?


    Thanks in advance


    Regards
    Sajjad

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Extend the ui_xxx.h file

    Quote Originally Posted by dosto.walla View Post
    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 View Post
    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

  3. The following user says thank you to jacek for this useful post:

    dosto.walla (2nd September 2008)

  4. #3
    Join Date
    Sep 2008
    Posts
    21
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Extend the ui_xxx.h file

    Does your CalculatorForm inherit QDialog?

  6. #5
    Join Date
    Sep 2008
    Posts
    21
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Extend the ui_xxx.h file

    Quote Originally Posted by dosto.walla View Post
    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.

  8. #7
    Join Date
    Sep 2008
    Posts
    21
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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*********** **********
    Qt Code:
    1. #ifndef CALCULATORFORM_H
    2. #define CALCULATORFORM_H
    3.  
    4. #include "ui_calculatorform.h"
    5.  
    6. class CalculatorForm : public QWidget
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11. CalculatorForm(QWidget *parent = 0);
    12.  
    13. private slots:
    14. void on_inputSpinBox1_valueChanged(int value);
    15. void on_inputSpinBox2_valueChanged(int value);
    16.  
    17. private:
    18. Ui::CalculatorForm ui;
    19. };
    20.  
    21. #endif
    To copy to clipboard, switch view to plain text mode 
    ***********************CalculatorForm.h*********** **********

    ***********************CalculatorForm.cpp********* ************
    Qt Code:
    1. #include <QtGui>
    2.  
    3. #include "CalculatorForm.h"
    4.  
    5. CalculatorForm::CalculatorForm(QWidget *parent)
    6. : QWidget(parent)
    7. {
    8. ui.setupUi(this);
    9. }
    10.  
    11. void CalculatorForm::on_inputSpinBox1_valueChanged(int value)
    12. {
    13. ui.outputWidget->setText(QString::number(value + ui.inputSpinBox2->value()));
    14. }
    15.  
    16. void CalculatorForm::on_inputSpinBox2_valueChanged(int value)
    17. {
    18. ui.outputWidget->setText(QString::number(value + ui.inputSpinBox1->value()));
    19. }
    To copy to clipboard, switch view to plain text mode 
    ***********************CalculatorForm.cpp********* ************



    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
    Last edited by jacek; 4th September 2008 at 20:12. Reason: missing [code] tags

  9. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Extend the ui_xxx.h file

    Quote Originally Posted by dosto.walla View Post
    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.

  10. #9
    Join Date
    Sep 2008
    Posts
    21
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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

    *****************

  11. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Extend the ui_xxx.h file

    Is your form named "CalculatorForm" (check the objectName property)?

  12. #11
    Join Date
    Sep 2008
    Posts
    21
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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

  13. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Extend the ui_xxx.h file

    Quote Originally Posted by dosto.walla View Post
    the objectName property is set to the value Form
    In that case you have to use Ui::Form not Ui::CalculatorForm.

  14. #13
    Join Date
    Sep 2008
    Posts
    21
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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

  15. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default 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

  16. #15
    Join Date
    Sep 2008
    Posts
    21
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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
    Attached Images Attached Images

  17. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Extend the ui_xxx.h file

    Quote Originally Posted by dosto.walla View Post
    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.

  18. #17
    Join Date
    Sep 2008
    Posts
    21
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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

  19. #18
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Extend the ui_xxx.h file

    Quote Originally Posted by dosto.walla View Post
    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 View Post
    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).

  20. The following user says thank you to jacek for this useful post:

    dosto.walla (15th September 2008)

  21. #19
    Join Date
    Sep 2008
    Posts
    21
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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
    Attached Files Attached Files

  22. #20
    Join Date
    Sep 2008
    Posts
    21
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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
    Attached Images Attached Images

Similar Threads

  1. Set up the Qt4.3.2 with Visual Studio 2005
    By lamoda in forum Installation and Deployment
    Replies: 6
    Last Post: 30th January 2008, 06:51
  2. file renaming on windows
    By jdd81 in forum Qt Programming
    Replies: 9
    Last Post: 2nd October 2007, 19:41
  3. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21
  4. Sending Binary File with QFTP
    By nbkhwjm in forum Newbie
    Replies: 2
    Last Post: 7th March 2007, 18:10
  5. QDirModel, Model/View, extend the file onfo
    By VlJE in forum Qt Programming
    Replies: 10
    Last Post: 11th December 2006, 10:56

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.