Results 1 to 6 of 6

Thread: Transition from QMainWindow to QWidget

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2010
    Location
    Israel
    Posts
    24
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Transition from QMainWindow to QWidget

    I have a strange problem. I've built an application in a QMainWindow class. But now I need to rebuild it into something that will share the main window with others. So I've built a new QMainWindow class that will house everything. window.h file:
    Qt Code:
    1. #ifndef WINDOW_H
    2. #define WINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include "widget.h"
    6.  
    7. namespace Ui {
    8. class window;
    9. }
    10.  
    11. class window : public QMainWindow
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. explicit window(QWidget *parent = 0);
    17. ~window();
    18.  
    19. private:
    20. Ui::window *ui;
    21. };
    22.  
    23. #endif // WINDOW_H
    To copy to clipboard, switch view to plain text mode 
    And then I've tried to rewrite the old main windows as a QWidget and have the window show it. widget.h file:
    Qt Code:
    1. #ifndef WIDGET_H
    2. #define WIDGET_H
    3.  
    4. #include <QWidget>
    5.  
    6. namespace Ui {
    7. class widget;
    8. }
    9.  
    10. class widget : public QWidget
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. explicit widget(QWidget *parent = 0);
    16. ~widget();
    17.  
    18. private:
    19. Ui::widget *ui;
    20. };
    21.  
    22. #endif // WIDGET_H
    To copy to clipboard, switch view to plain text mode 
    This the code I use minus the internal methods. And the compilation error is on first line of the widget constructor:
    Qt Code:
    1. widget::widget(QWidget *parent) : QWidget(parent), ui(new Ui::widget)
    To copy to clipboard, switch view to plain text mode 
    Which says "invalid use of incomplete type 'struct Ui::widget'".

    Now, I've tried looking it up and I've found that this kind of error usually occurs through recursive definitions and integrations where by the time the compiler is doing the line in error, it needs definitions that won't become available until later on or even inside the class.
    Following the instructions on building an example, I did manage to write pretty much the same thing from scratch with, as far as I can see, the same code as the one I pasted and it works perfectly.

    So, my question is, did anyone already try doing what I did and can tell me what I'm doing wrong or any suggestions on how I can do it without writing the whole thing from scratch? Because right now it seems like I have to and I'd like to avoid it.

    Proper notice: I am a newbie to Qt and am still using a lot of automatics like the Designer, the automatic slot connection and the likes...
    Last edited by Sabre Runner; 12th October 2010 at 16:06.

Similar Threads

  1. QMenubar in a non mainwindow widget
    By Tito in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 16th August 2010, 15:24
  2. Replies: 10
    Last Post: 29th May 2010, 18:42
  3. graphicsView and widget embedding
    By wagmare in forum Qt Programming
    Replies: 1
    Last Post: 17th July 2009, 16:14
  4. Replies: 0
    Last Post: 4th February 2009, 14:46
  5. QwtPlot widget in MainWindow
    By sabeesh in forum Qt Programming
    Replies: 1
    Last Post: 25th July 2007, 11:48

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
  •  
Qt is a trademark of The Qt Company.