Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. [SOLVED] Qt Creator/Designer: Blank Main Window
QtWS25 Last Chance

[SOLVED] Qt Creator/Designer: Blank Main Window

Scheduled Pinned Locked Moved Qt Creator and other tools
12 Posts 3 Posters 10.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tyrn
    wrote on last edited by
    #3

    [quote author="RazrFalcon" date="1327342588"]Can you give your code to test it?[/quote]

    Are you sure it's necessary, RazrFalcon? Should be something trivial in the bulky generated code; but if you wish...

    Code deleted as irrelevant

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tobias.hunger
      wrote on last edited by
      #4

      The small window you see when running your application is a normal, empty MainWindow. Add your UI to it if you want to actually see it.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Tyrn
        wrote on last edited by
        #5

        [quote author="Tobias Hunger" date="1327398398"]The small window you see when running your application is a normal, empty MainWindow. Add your UI to it if you want to actually see it.[/quote]

        But what exactly is this tiny step? Is it necessarily manual? The step-by-step guide fails to mention it. Press Ctrl+R and watch the fun, they say.

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tobias.hunger
          wrote on last edited by
          #6

          The tutorial is written for Qt Designer, you seem to be using Qt Creator, which has similar functionality built-in.

          In Qt Designer Ctrl-R is the key combo to trigger a preview. That is used to run your project in Qt Creator. Try hitting Alt-Shift-R in Qt Creator instead.

          1 Reply Last reply
          0
          • T Offline
            T Offline
            Tyrn
            wrote on last edited by
            #7

            [quote author="Tobias Hunger" date="1327405815"]Try hitting Alt-Shift-R in Qt Creator instead.[/quote]
            Alt-Shift-R works, thanks! But why is the UI disconnected when I start it as an app?

            I've been studying this demo: http://www.youtube.com/watch?v=JtyCM4BTbYo

            There's some curious difference:

            Mine mainwindow.cpp:
            @#include "mainwindow.h"

            MainWindow::MainWindow(QWidget *parent)
            : QMainWindow(parent)
            {
            }

            MainWindow::~MainWindow()
            {

            }
            @

            His:

            @#include "mainwindow.h"
            #include "ui_mainwindow.h"

            MainWindow::MainWindow(QWidget *parent)
            : QMainWindow(parent)
            , ui(new Ui::MainWindow)
            {
            ui->setupUi(this);
            }

            MainWindow::~MainWindow()
            {
            delete ui;
            }
            @

            His variant seems to be generated; in my case it would have taken some tampering with (re)generated files, which is obviously no good.

            Besides, my ui_mainwindow.h gets generated into ...-build-desktop-Qt_in_PATH_Debug directory. Is it OK?
            It feels like some project wizard option has been chosen wrong.

            1 Reply Last reply
            0
            • T Offline
              T Offline
              tobias.hunger
              wrote on last edited by
              #8

              Your UI is disconnected since there is no code that actually adds your UI to the MainWindow.

              "His" code does just that... Note that there is some definition of "ui" in his mainwindow.h that is also needed.

              Any files that will be regenerated tend to have a comment right at the top, saying just that. Keep away from those, but feel free to edit all the others. They might be generated, but they are meant to be edited by you and will not get regenerated later.

              That ui_mainwindow.h gets put into the build directory (...-build-...) is called shadow building. This means that all generated files will end up in the build directory, keeping your source directory clean. This is what should happen:-)

              1 Reply Last reply
              0
              • T Offline
                T Offline
                Tyrn
                wrote on last edited by
                #9

                [quote author="Tobias Hunger" date="1327413569"]Your UI is disconnected since there is no code that actually adds your UI to the MainWindow.

                "His" code does just that... Note that there is some definition of "ui" in his mainwindow.h that is also needed.

                Any files that will be regenerated tend to have a comment right at the top, saying just that.[/quote]

                I still can't figure the thing out. I tried this:

                @#ifndef MAINWINDOW_H
                #define MAINWINDOW_H

                #include <QtGui/QMainWindow>

                class MainWindow : public QMainWindow
                {
                Q_OBJECT

                public:
                MainWindow(QWidget parent = 0);
                ~MainWindow();
                void
                ui;
                };

                #endif // MAINWINDOW_H
                @

                mainwindow.cpp:

                @#include "mainwindow.h"
                #include"ui_mainwindow.h"

                MainWindow::MainWindow(QWidget *parent)
                : QMainWindow(parent)
                {
                ui = new Ui::MainWindow;
                static_castUi::MainWindow*(ui)->setupUi(this);
                }

                MainWindow::~MainWindow()
                {
                delete static_castUi::MainWindow*(ui);
                }
                @

                It looks ugly, and it won't work. Compilation errors in ui_mainwindow.h.

                I've got some trouble believing that the matter is considered too trivial to be mentioned in a tutorial for dummies.

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  tobias.hunger
                  wrote on last edited by
                  #10

                  Use Ui::MainWindow * as type for ui (line 13 of mainwindow.h). That saves you from doing all those ugly casts. Way less ugly that way:-)

                  Is there a ui_mainwindow.h somewhere? Try a clean rebuild. It is hard to say what is wrong without the error message.

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    Tyrn
                    wrote on last edited by
                    #11

                    [quote author="Tobias Hunger" date="1327418625"]Is there a ui_mainwindow.h somewhere? Try a clean rebuild. It is hard to say what is wrong without the error message.[/quote]

                    Yes, there is. Clean rebuild and all. I've made some progress:
                    @#ifndef MAINWINDOW_H
                    #define MAINWINDOW_H

                    #include <QtGui/QMainWindow>

                    namespace Ui
                    {
                    class MainWindow;
                    }

                    class MainWindow : public QMainWindow
                    {
                    Q_OBJECT

                    public:
                    MainWindow(QWidget parent = 0);
                    ~MainWindow();
                    private:
                    Ui::MainWindow
                    ui;
                    };

                    #endif // MAINWINDOW_H
                    @
                    @#include "mainwindow.h"
                    #include"ui_mainwindow.h"

                    MainWindow::MainWindow(QWidget *parent)
                    : QMainWindow(parent)
                    , ui(new Ui::MainWindow)
                    {
                    ui->setupUi(this);
                    }

                    MainWindow::~MainWindow()
                    {
                    delete ui;
                    }
                    @

                    Still, there's an error: "Undefined reference to 'QWebView::QWebView(QWidget*)' in ui_mainwindow.h"

                    There is
                    @#include <QtWebKit/QWebView>@

                    in ui_mainwindow.h

                    1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      Tyrn
                      wrote on last edited by
                      #12

                      To wrap it up:

                      (1) If you need something esoteric, like QtWebKit, you'll have to put it into your project:
                      @#-------------------------------------------------

                      Project created by QtCreator 2012-01-24T22:17:48

                      #-------------------------------------------------

                      QT += core gui webkit

                      TARGET = MiBrowser
                      TEMPLATE = app

                      SOURCES += main.cpp
                      mainwindow.cpp

                      HEADERS += mainwindow.h

                      FORMS += mainwindow.ui
                      @

                      (2) If you postpone the creation of the main form, you'd better create Qt Designer Form Class rather than Qt Designer Form, when it comes to it.

                      Thanks, Tobias!

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved