Results 1 to 8 of 8

Thread: Generated UI header incorrectly includes class header?

  1. #1
    Join Date
    Dec 2011
    Posts
    27
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Generated UI header incorrectly includes class header?

    Hello all,

    I'm having an issue wherein for a particular .ui file, the auto-generated ui header is trying to include the core class header, and failing.

    That is, I have a QWidget-derived class, called slimWindow, and when building via Qt Creator, it generates the ui_slimwindow.h file, which tries to #include "slimwindow.h", which of course fails (that file doesn't get moved to the .ui directory during build).

    The odd thing is, this error started when the class was moved from one subdirectory to another, even though the .pri file including it is correct, and everything works otherwise. I have many other ui files, and none of the rest do this. Telling in the symptoms is that the generated ui header doesn't declare the new object as a QWidget, like all of the other QWidget-derived headers, but instead declares it an instance of its own class, see:

    Qt Code:
    1. /********************************************************************************
    2. ** Form generated from reading UI file 'slimwindow.ui'
    3. **
    4. ** Created: Tue Jun 12 17:19:52 2012
    5. ** by: Qt User Interface Compiler version 4.8.0
    6. **
    7. ** WARNING! All changes made in this file will be lost when recompiling UI file!
    8. ********************************************************************************/
    9.  
    10. #ifndef UI_SLIMWINDOW_H
    11. #define UI_SLIMWINDOW_H
    12.  
    13. #include <QtCore/QVariant>
    14. #include <QtGui/QAction>
    15. #include <QtGui/QApplication>
    16. #include <QtGui/QButtonGroup>
    17. #include <QtGui/QGridLayout>
    18. #include <QtGui/QHBoxLayout>
    19. #include <QtGui/QHeaderView>
    20. #include <QtGui/QLineEdit>
    21. #include <QtGui/QPushButton>
    22. #include <QtGui/QSpacerItem>
    23. #include <QtGui/QTableView>
    24. #include <QtGui/QTextEdit>
    25. #include "slimwindow.h"
    26.  
    27. QT_BEGIN_NAMESPACE
    28.  
    29. class Ui_SlimWindow
    30. {
    31. public:
    32. QGridLayout *gridLayout_2;
    33. QGridLayout *gridLayout;
    34. QHBoxLayout *horizontalLayout_2;
    35. QSpacerItem *horizontalSpacer;
    36. QLineEdit *commandInputLine;
    37. QPushButton *goButton;
    38. QHBoxLayout *horizontalLayout_4;
    39. QTableView *historyTableView;
    40. QTextEdit *commandResults;
    41.  
    42. void setupUi(SlimWindow *SlimWindow)
    43.  
    44. ...
    To copy to clipboard, switch view to plain text mode 

    Whereas, for all other QWidget-derived classes with ui files, the generated code looks as follows:

    Qt Code:
    1. ...
    2.  
    3. #include <QtGui/QLabel>
    4. #include <QtGui/QListView>
    5. #include <QtGui/QPushButton>
    6. #include <QtGui/QScrollArea>
    7. #include <QtGui/QSpacerItem>
    8. #include <QtGui/QSpinBox>
    9. #include <QtGui/QToolButton>
    10. #include <QtGui/QVBoxLayout>
    11. #include <QtGui/QWidget>
    12.  
    13. QT_BEGIN_NAMESPACE
    14.  
    15. class Ui_filmWindow
    16. {
    17. ...
    18.  
    19. QPushButton *pushButton_11;
    20. QPushButton *pushButton_10;
    21. QPushButton *pushButton_9;
    22.  
    23. void setupUi(QWidget *filmWindow)
    24.  
    25. ...
    To copy to clipboard, switch view to plain text mode 

    This happens on both OSX and Windows during compile. I know that I can change include paths and the issue will "disappear", but that seems like a cover-up over a bigger problem. Has anyone seen similar behavior before? I saw one post regarding it, but the suggested, and followed, solution was to cover up the issue by modifying the include paths so that including a file not in the current directory would work.

    Without posting mountains of code, as the project is fairly complex I'm hoping the following parts will be sufficient in pointing out what I might've done wrong?:

    slim.pri:

    Qt Code:
    1. DEFINES += QT_USE_QSTRINGBUILDER
    2.  
    3. HEADERS += \
    4. slim/slimwindow.h \
    5. slim/SlimFileHandler/slimfilehandler.h
    6.  
    7. SOURCES += \
    8. slim/slimwindow.cpp \
    9. slim/SlimFileHandler/slimfilehandler.cpp
    10.  
    11. FORMS += \
    12. slim/slimwindow.ui
    To copy to clipboard, switch view to plain text mode 

    slimwindow.h:

    Qt Code:
    1. #ifndef SLIMWINDOW_H
    2. #define SLIMWINDOW_H
    3.  
    4. #include <QWidget>
    5. #include <QString>
    6.  
    7. #include "MoCoBus/omcommandbuffer.h"
    8. #include "MoCoBus/omnetwork.h"
    9. #include "Slim/commandhistorymodel.h"
    10. #include "Slim/slimcommandparser.h"
    11.  
    12. namespace Ui {
    13. class SlimWindow;
    14. }
    15.  
    16. class SlimWindow : public QWidget
    17. {
    18. Q_OBJECT
    19.  
    20. public:
    21. SlimWindow(OMNetwork* net, CommandHistoryModel* hist, SlimCommandParser* parse, QWidget *parent = 0);
    22. ~SlimWindow();
    23.  
    24. private slots:
    25. void onCmdEntry();
    26. void onCmdResult(slimCommand);
    27.  
    28. public slots:
    29. void registerNewDevice(OMbusInfo* p_bus, OMdeviceInfo* p_dev);
    30. void removeDevice(OMbusInfo* p_bus, unsigned short p_addr);
    31. private:
    32.  
    33. Ui::SlimWindow *ui;
    34. CommandHistoryModel* _cmdHist;
    35. OMNetwork* _net;
    36. SlimCommandParser * _parser;
    37. };
    38.  
    39.  
    40. #endif // SLIMWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    slimwindow.cpp (just up to, and including, the constructor) :

    Qt Code:
    1. #include "slimwindow.h"
    2. #include "ui_slimwindow.h"
    3.  
    4.  
    5. #include <QDebug>
    6. #include <QtEndian>
    7.  
    8. #include "Core/ErrorDialog/errordialog.h"
    9.  
    10.  
    11. SlimWindow::SlimWindow(OMNetwork* net, CommandHistoryModel* hist, SlimCommandParser* parse, QWidget *parent) :
    12. QWidget(parent),
    13. ui(new Ui::SlimWindow)
    14. {
    15.  
    16. ui->setupUi(this);
    17.  
    18. _parser = parse;
    19. _net = net;
    20. _cmdHist = hist;
    21.  
    22. ui->historyTableView->setModel(_cmdHist);
    23.  
    24. QObject::connect(_cmdHist, SIGNAL(commandResults(slimCommand)), this, SLOT(onCmdResult(slimCommand)), Qt::QueuedConnection);
    25.  
    26.  
    27. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Generated UI header incorrectly includes class header?

    Any chance of posting the *.ui file, since it is the only one that matters when it comes to generating the ui_*h file. Generally you get non-Qt includes only when you use the Promotion mechanism in the UI design.

  3. The following 2 users say thank you to ChrisW67 for this useful post:

    alistair (18th August 2015), droneone (14th June 2012)

  4. #3
    Join Date
    Dec 2011
    Posts
    27
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Generated UI header incorrectly includes class header?

    I think you hit the nail on the head there... I see now what's different about this one, namely:

    Qt Code:
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <ui version="4.0">
    3. <class>SlimWindow</class>
    4. <widget class="SlimWindow" name="SlimWindow">
    To copy to clipboard, switch view to plain text mode 

    I see also that it does show as promoted in the Designer UI. Is there a way, short of editing the ui file outside of Qt Creator to un-promote this widget? The docs indicate there should be a "Demote to" context option, which does not appear when I right-click on the widget?

    (Edit was because I had some issues with quick reply timing out, removed bad replies)
    Last edited by droneone; 14th June 2012 at 02:28.

  5. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Generated UI header incorrectly includes class header?

    AFAICT Designer does not allow you to promote the top-most widget in the design in the first place. How did you get to this point?

    You should be able to make line 4 read:
    Qt Code:
    1. <widget class="QWidget" name="SlimWindow">
    To copy to clipboard, switch view to plain text mode 
    but there will be other elements in the <customwidgets> part of the file related to the "promoted" widget including what headers to include.

    Another approach would be to copy and paste this design's content into a new one.

  6. #5
    Join Date
    Dec 2011
    Posts
    27
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Generated UI header incorrectly includes class header?

    Quote Originally Posted by ChrisW67 View Post
    AFAICT Designer does not allow you to promote the top-most widget in the design in the first place. How did you get to this point?

    You should be able to make line 4 read:
    Qt Code:
    1. <widget class="QWidget" name="SlimWindow">
    To copy to clipboard, switch view to plain text mode 
    but there will be other elements in the <customwidgets> part of the file related to the "promoted" widget including what headers to include.

    Another approach would be to copy and paste this design's content into a new one.
    Chris,

    Thanks for your help - now, as to how it got this way? That's a good question - but I see that designer does not seem to prevent me from promoting a top-level widget in a form, I just have to type in the name, and it seems to do it. After manually removing all of the promoted content, I finally found how to demote a widget via designer (even though everything is removed from that ui file, I'm guessing the .pro.user retains some information). You right-click any widget, select "promoted widgets", then click on the one you want to get rid of, and a '-' icon appears now. Wish I had noticed that last night =)

    FYI, in addition to changing the class of the widget, one would also want to look for xml like:

    Qt Code:
    1. <customwidgets>
    2. <customwidget>
    3. <class>SlimWindow</class>
    4. <extends>QWidget</extends>
    5. <header>slimwindow.h</header>
    6. <container>1</container>
    7. </customwidget>
    8. </customwidgets>
    To copy to clipboard, switch view to plain text mode 

    Thanks again!

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Generated UI header incorrectly includes class header?

    Quote Originally Posted by droneone View Post
    but I see that designer does not seem to prevent me from promoting a top-level widget in a form
    My Designer does not allow me to do so. Of course provided we all understand the term "top level widget" the same way. I'm talking about right clicking a blank form and looking for "Promote to..." menu entry which is not there.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #7
    Join Date
    Dec 2011
    Posts
    27
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Generated UI header incorrectly includes class header?

    Quote Originally Posted by wysota View Post
    My Designer does not allow me to do so. Of course provided we all understand the term "top level widget" the same way. I'm talking about right clicking a blank form and looking for "Promote to..." menu entry which is not there.
    Ahh, I am using the designer inside of Creator 2.4.1, and it doesn't have a 'promote to', as far as I can see when right-clicking a blank form - but instead, when I click on any widget on the right (in the list of widgets, including the top-level one), it has a "Promoted Widgets" option, which once opened, allows one to manually define a new promoted class by simply choosing the base class, typing the promoted class name, and specifying the header file. This appears to be the same dialog I get when I click "promote to" on any widget included in a form.

  9. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Generated UI header incorrectly includes class header?

    Quote Originally Posted by droneone View Post
    Ahh, I am using the designer inside of Creator 2.4.1, and it doesn't have a 'promote to', as far as I can see when right-clicking a blank form - but instead, when I click on any widget on the right (in the list of widgets, including the top-level one), it has a "Promoted Widgets" option, which once opened, allows one to manually define a new promoted class by simply choosing the base class, typing the promoted class name, and specifying the header file. This appears to be the same dialog I get when I click "promote to" on any widget included in a form.
    This dialog does not allow you to PROMOTE the top-level widget, only provides a way to define mappings for promotions (the "Promote" button is greyed out).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 3
    Last Post: 6th December 2010, 14:23
  2. QStandardItem's header item and header label
    By feverzsj in forum Newbie
    Replies: 1
    Last Post: 14th January 2010, 19:57
  3. Form generated header files
    By Rockem in forum Qt Programming
    Replies: 3
    Last Post: 20th August 2009, 12:55
  4. How to customize horizontal header (diagonal header view)
    By vairamuthu.g in forum Qt Programming
    Replies: 4
    Last Post: 4th September 2008, 15:59
  5. class header warnings.
    By impeteperry in forum Newbie
    Replies: 9
    Last Post: 31st May 2006, 05:30

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.