Results 1 to 3 of 3

Thread: Using Designer output in VS 2008 Standard

  1. #1
    Join Date
    Oct 2009
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Using Designer output in VS 2008 Standard

    I just created my first non-hand-coded Qt GUI using Designer but I don't know how to use the result in my other QDialog derived C++ class. I created a complex widget using Designer and this resulted in a VisControls.ui file. After it compiled, I had ui_VisControls.h which contains the UI code with 2 classes: Ui_VisControls and an emty class Ui::VisControls : Ui_VisControls.

    I tried:

    #include "GeneratedFiles/ui_VisControls.h"
    using Ui;
    ...
    VisControls *w = new VisControls();
    w->Show();

    Then got the compiler error 'Show' is not a member of Ui::VisControls. This makes sense because nowhere in the generated files that I can find is there a " : QWidget" making the class I created derive from QWidget. Neither Ui_VisControls or Ui::VisControls derives from QWidget. Since the ui_VisControls.h file is regenerated when I compile, I can't very well add " : QWidget" there.

    All I am looking for is how to take the output of Designer and then instantiate QWidget-derived classes. That is, how do I plug the results of Designer into my applications?

    I've been using Qt in Visual Studio 2008 Standard for a couple of months with no problems.

    I must be making a simple mistake because the property editor in Designer has QWidget attributes. I saw no place in Designer where I could specify the base class when creating my new Form.

    Sorry for the dumb question! Below is the code where I want to display my form. The .ui and generated .h files are too large to attach in this forum so I included excerpts below.

    Thank you in advance. I have looked at this problem for hours but to no avail.

    Rick

    ------------------------------------------------

    ui_VisControls.h excerpt:

    Qt Code:
    1. #ifndef UI_VISCONTROLS_H
    2. #define UI_VISCONTROLS_H
    3.  
    4. #include <QtCore/QVariant>
    5. #include <QtGui/QAction>
    6. #include <QtGui/QApplication>
    7. #include <QtGui/QButtonGroup>
    8. #include <QtGui/QDoubleSpinBox>
    9. #include <QtGui/QGroupBox>
    10. #include <QtGui/QHeaderView>
    11. #include <QtGui/QLabel>
    12. #include <QtGui/QPushButton>
    13. #include <QtGui/QSlider>
    14. #include <QtGui/QSpinBox>
    15. #include <QtGui/QWidget>
    16.  
    17. QT_BEGIN_NAMESPACE
    18.  
    19. class Ui_VisControls
    20. {
    21. public:
    22. QGroupBox *groupBox;
    23. QSlider *cameraPositionXSlider;
    24. QSlider *cameraPositionXYSlider;
    25. QSlider *cameraPositionZSlider;
    26. < many more lines... >
    To copy to clipboard, switch view to plain text mode 

    ------------------------------------------------

    Here is an excerpt from the .ui file:

    Qt Code:
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <ui version="4.0">
    3. <class>VisControls</class>
    4. <widget class="QWidget" name="VisControls">
    5. <property name="geometry">
    6. <rect>
    7. <x>0</x>
    8. <y>0</y>
    9. <width>281</width>
    10. <height>761</height>
    11. </rect>
    12. </property>
    13. <property name="windowTitle">
    14. <string>VisControls</string>
    15. </property>
    16. <widget class="QGroupBox" name="groupBox">
    17. <property name="geometry">
    18. <rect>
    19. <x>10</x>
    20. <y>10</y>
    21. <width>261</width>
    22. <height>81</height>
    23. </rect>
    24. </property>
    25. <property name="title">
    26. <string> Camera Position </string>
    27. </property>
    28. <widget class="QSlider" name="cameraPositionXSlider">
    29. <property name="geometry">
    30. <rect>
    31. <x>30</x>
    32. < many more lines >
    To copy to clipboard, switch view to plain text mode 

    ------------------------------------------------

    This is the place where I attempted to use the Designer-generated class:

    Qt Code:
    1. #include "GeneratedFiles/ui_VisControls.h"
    2. using namespace Ui;
    3. ...
    4. void OpenGLDlg3::test1ButtonPressed() {
    5. VisControls *w = new VisControls();
    6. w->Show();
    7. emit test1();
    8. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Using Designer output in VS 2008 Standard

    If you look into the ui_*.h file, you should see a method setupui(). You should call that, giving it the parent widget to populate with controls.

    You could also drop a qwidget on the main form with designer, and then promote it to your new class.

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

    rtc1 (29th November 2009)

  4. #3
    Join Date
    Oct 2009
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Using Designer output in VS 2008 Standard

    Thanks! After reading your posting, I Googled setupui and found this link which explains things very well:

    http://qt.nokia.com/doc/4.0/porting4-designer.html

    Thanks again!
    Last edited by rtc1; 29th November 2009 at 17:26. Reason: spelling error

Similar Threads

  1. assembler error in qt
    By guruvadhiraj in forum Installation and Deployment
    Replies: 9
    Last Post: 12th October 2011, 07:54
  2. Compile problem: Qt4.5.1 opensource, VisualStudio 2008 Standard
    By wally in forum Installation and Deployment
    Replies: 2
    Last Post: 28th May 2009, 15:42
  3. How to Compile VTKDesigner2 with Qt?
    By alfredoaal in forum Newbie
    Replies: 0
    Last Post: 5th September 2008, 05:34
  4. Replies: 2
    Last Post: 2nd June 2008, 08:45
  5. redirection of standard input and output
    By guestgulkan in forum Qt Programming
    Replies: 2
    Last Post: 15th October 2006, 20:30

Tags for this Thread

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.