user453575457
user453575457

Reputation: 602

How to show the QML window before the program is completed?

The problem is simple: window doesn't rendering and refresh, until the program is finished. It just doesn't show anything. And I want to see the window even if the long cycle is not finished yet. I will be very grateful for any help!

#include <QtGui>
#include <QtQml>

int main(int _nArgCount, char * _pArgValues[]) {
    QApplication app(_nArgCount, _pArgValues);

    //QMLblock
    QString strQmlPath = "../main.qml";
    QQmlApplicationEngine engine;
    QQmlComponent pComponent(&engine, strQmlPath);
    if( pComponent.status()==QQmlComponent::Error )
           { qDebug()<<"Error:"<<pComponent.errorString();
              return app.exec();
           }
    QObject * pQmlObject = pComponent.create();

    QObject * pWindow = pQmlObject->findChild<QObject*>("initStateGui");
    QObject * pWindowNext = pQmlObject->findChild<QObject*>("searchRemovableGui");
    pWindow->setProperty("visible","false");
    pWindowNext->setProperty("visible","true");
    QObject * pList = pQmlObject->findChild<QObject*>("devicesList");
    QStringList s;
    QString str;

    s.append("3");
    pList->setProperty("model",s);

        for (int i=0; i<5; i++){
        s.append(str.number(i));
        pList->setProperty("model",s);

    }


   return app.exec();

}

And my QML (I don't think it's needed, but anyway):

import QtQuick 2.3
import QtQuick.Controls 1.2
import QtQuick.Window 2.2

QtObject {
    property real defaultSpacing: 10
    property SystemPalette palette: SystemPalette { }

    property var controlWindow: Window {
        width: 500
        height: 500
        color: palette.window
        title: "Updater"
        visible: true
        //init state
        Column {
            id: initStateGui
            objectName: "initStateGui"
            anchors.fill: parent
            anchors.margins: defaultSpacing
            spacing: defaultSpacing
            property real cellWidth: initStateGui.width / 3 - spacing
            visible: true
            Text { text: "Init state" }
            Grid {
                id: grid
                columns: 3
                spacing: defaultSpacing
                width: parent.width
                Button {
                    id: showButton
                    width: initStateGui.cellWidth
                    text: "Cancel"
                    onClicked: Qt.quit()
                }

                Button {
                    id: initStateContinue
                    objectName: "initStateContinue"
                    width: initStateGui.cellWidth
                    text: "Continue"
                    signal sigInitStateContinue()
                    onClicked: initStateContinue.sigInitStateContinue()

                }

            }

            Text {
                id: textLabel
                text: "Welcome to the updater!"
            }
            Rectangle {
                id: horizontalRule
                color: "black"
                width: parent.width
                height: 1
            }

        }

        //updater update state
        Column {
            id: updaterUpdateGui
            objectName: "updaterUpdateGui"
            anchors.fill: parent
            anchors.margins: defaultSpacing
            spacing: defaultSpacing
            visible: false
            property real cellWidth: initStateGui.width / 3 - spacing
            Text { text: "UpdaterUpdate State" }
            Grid {
                id: grid1
                columns: 3
                spacing: defaultSpacing
                width: parent.width
                Button {
                    id: showButton1
                    width: initStateGui.cellWidth
                    text: "Cancel"
                    onClicked: Qt.quit()
                }
                Button {
                    id: updaterUpdateContinue
                    objectName: "updaterUpdateContinue"
                    width: initStateGui.cellWidth
                    text: "Continue"
                    signal sigUpdaterUpdateContinue()
                    onClicked: updaterUpdateContinue.sigUpdaterUpdateContinue()

                }

            }

            Text {
                text: "Update is started!"
            }
            Rectangle {
                id: horizontalRule1
                color: "black"
                width: parent.width
                height: 1
            }

        }

        //removable Search gui
        Column {
            id:searchRemovableGui
            objectName: "searchRemovableGui"
            anchors.fill: parent
            anchors.margins: defaultSpacing
            spacing: defaultSpacing
            visible: false
            property real cellWidth: initStateGui.width / 3 - spacing
            Text { text: "Removable search State" }
            Grid {
                id: grid2
                columns: 3
                spacing: defaultSpacing
                width: parent.width
                Button {
                    id: showButton2
                    width: initStateGui.cellWidth
                    text: "Cancel"
                    onClicked: Qt.quit()
                }
            }

            Text {
                text: "Searching for removable, please wait...!"
            }




            ListView {
                id:devicesList
                objectName:"devicesList"
                width: 100; height: 500
                model: myModel
                delegate: Rectangle {
                    height: 15
                    width: 100
                    Text { text: modelData }


                }
            }

        }
    }
}

Addition: i don't need threads, i need to see the freezed window with the caption.

I see it if i add the button, and begin cycle after the button is pressed. Without the button the window doesn't rendering, and i can't find how to do it.

Upvotes: 0

Views: 597

Answers (1)

user453575457
user453575457

Reputation: 602

It's impossible to realize in one thread. Only moving long process to another thread allows to render GUI.

Upvotes: 1

Related Questions