How to show the mainwindow.ui



  • I am new to QT. I've just created a pro project and added Form Class. I designed my mainwindow.ui but how should I show that? I want to start the app with that windows? I am a mac user.



  • You can install "QtCreator":http://get.qt.nokia.com/qtcreator/qt-creator-mac-opensource-2.3.1.dmg and create new project with QtCreator and you'll see realisation of such application.

    Here is the default defenition of MainWindow with form created by QtCreator


    main.cpp:

    @
    #include <QtGui/QApplication>
    #include "mainwindow.h"

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec&#40;&#41;;
    

    }
    @


    Header mainwinwow.h:

    @
    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>

    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    private:
    Ui::MainWindow *ui;
    };

    #endif // MAINWINDOW_H
    @


    Source 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;
    }
    @


    and mainwindow.pro file:

    @

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

    Project created by QtCreator 2011-11-02T08:56:38

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

    QT += core gui

    TARGET = MainWindow
    TEMPLATE = app

    SOURCES += main.cpp
    mainwindow.cpp

    HEADERS += mainwindow.h

    FORMS += mainwindow.ui
    @

    P.S. -QT- it's QuickTime so it is Qt



  • I am using QTCreator, but tell me how to show my main window.ui instead of main.qml



  • If you are using qml, you should stay in qml, especially at the beginning.

    Seems, you created a Qt Quick project (which is qml).
    For starting with Qt, I suggest creating a "normal" Qt project, like
    Qt-Widget-Project --> Qt-Gui_...



  • I am writing a compiler. It's finished. I want to create GUI. I've choose QT because it has Ubuntu output. I'm good at C++. Why should I stay at QML?



  • Your posts states that you created something with qml. If you created a "normal" qt gui project based on a main w9indow, it would work out of the box ;-)



  • I changed it to the GUI widget but i don't know how to manage my objects. for example; I want to change the text box text when the button is pressed. Bot of them are created and there s function for the pushButton when pressed


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.