Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. It output nothing without error code!!
Forum Updated to NodeBB v4.3 + New Features

It output nothing without error code!!

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
8 Posts 3 Posters 703 Views 1 Watching
  • 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.
  • D Offline
    D Offline
    diuneiguohai
    wrote on last edited by
    #1

    Thanks for reading. I am very new to qml.
    It outputs nothing even the ui even when i comment out the whole testingtext.h!!
    I do not know what happened. here is my code

    .pro

    QT += quick
    QT += qml
    CONFIG += c++11
    CONFIG += qmltypes
    QML_IMPORT_NAME = Charts
    QML_IMPORT_MAJOR_VERSION = 1
    
    # You can make your code fail to compile if it uses deprecated APIs.
    # In order to do so, uncomment the following line.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    
    SOURCES += \
            main.cpp \
            testingtext.cpp
    
    RESOURCES += qml.qrc
    
    TRANSLATIONS += \
        kpp_main_system_yue_HK.ts
    
    # Additional import path used to resolve QML modules in Qt Creator's code model
    QML_IMPORT_PATH =
    
    # Additional import path used to resolve QML modules just for Qt Quick Designer
    QML_DESIGNER_IMPORT_PATH =
    
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    
    HEADERS += \
        testingtext.h
    
    

    main.cpp

    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    #include <QDebug>
    #include <QQmlContext>
    #include "testingtext.h"
    
    int main(int argc, char *argv[])
    {
        QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
        QGuiApplication app(argc, argv);
    
        qmlRegisterType<testingtext>("testingtext", 1, 0, "Testingtext");
    
        QQmlApplicationEngine engine;
    
        const QUrl url(QStringLiteral("qrc:/main.qml"));
        QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                         &app, [url](QObject *obj, const QUrl &objUrl) {
            if (!obj && url == objUrl)
                QCoreApplication::exit(-1);
        }, Qt::QueuedConnection);
        engine.load(url);
    
        return app.exec();
    }
    
    

    textingtext.h

    #include <QtQuick/QQuickPaintedItem>
    #include <QString>
    #include <QColor>
    #include <QObject>
    
    class testingtext : public QObject
    {
        Q_OBJECT
        Q_PROPERTY(QString on9text MEMBER on9text NOTIFY on9textchanged)
        QML_ELEMENT
    
    public:
    
        explicit testingtext(QObject *parent =nullptr);
    
    signals:
        void on9textchanged();
    
    
    private:
        QString text= "on9";
    
    
    
        QString on9text = "";
        void seton9text();
    
    
    };
    
    

    testingtext.cpp

    #include "testingtext.h"
    
    testingtext:: testingtext(QObject *parent): QObject(parent){
    
    }
    
    QString on9text(){
       return "on9";
    }
    
    

    main.qml

    import QtQuick 2.15
    import QtQuick.Controls 2.15
    import testingtext 1.0
    
    Item {
        id: root
        width:1280
        height: 720
        Rectangle {
            id: rectangle1
    
            color: "grey"
            anchors.fill: parent
    
            Testingtext {
                id: testingtext
            }
    
            RoundButton {
                id: button2
                x: 441
                y: 12
                width: 200
                height: 68
                radius: 8
                text: qsTr("Button")
                anchors.left: tab1.right
                anchors.top: tab1.top
                anchors.bottom: rectangle.top
                topPadding: 6
                anchors.bottomMargin: -6
                anchors.topMargin: 0
                anchors.leftMargin: 8
            }
    
            RoundButton {
                id: button1
                x: 600
                y: 12
                width: 200
                height: 68
                radius: 8
                text: qsTr("Button")
                anchors.left: tab1.right
                anchors.top: tab1.top
                anchors.bottom: rectangle.top
                topPadding: 6
                anchors.bottomMargin: -6
                anchors.topMargin: 0
                anchors.leftMargin: 8
            }
    
    
            RoundButton {
                id: button
                width: 200
                height: 68
                radius: 8
                text: qsTr("Button")
                anchors.left: button1.right
                anchors.bottom: rectangle.top
                anchors.leftMargin: 8
                anchors.bottomMargin: -8
                topPadding: 6
            }
    
            Rectangle {
                id: rectangle
                color: "#ffffff"
                radius: 20
                anchors.top: parent.top
                anchors.bottom: parent.bottom
                rotation: 0
                anchors.rightMargin: 16
                anchors.leftMargin: 16
                anchors.bottomMargin: 24
                anchors.topMargin: 72
                anchors.horizontalCenterOffset: 4
                anchors.horizontalCenter: parent.horizontalCenter
    
                TextInput {
                    id: textInput
                    x: 187
                    y: 288
                    width: 80
                    height: 20
                    text: testingtext.on9text
                    font.pixelSize: 12
                }
            }
    
            Rectangle {
                id: tab1
                width: 200
                height: 200
                color: "#ffffff"
                radius: 8
                anchors.left: rectangle.left
                anchors.top: rectangle.top
                anchors.leftMargin: 0
                anchors.topMargin: -60
            }
    
    
    
    
        }
    
    
    
    }
    
    

    it is probaly a very dumb mistake that i cant spot!
    Again! thanks for your time reading this!

    ODБOïO 1 Reply Last reply
    0
    • MarkkyboyM Offline
      MarkkyboyM Offline
      Markkyboy
      wrote on last edited by
      #2

      You're not making it easy on yourself or others who may be able to help. Although I'm not sure how to actually do it, you are better off putting your code on Github, making it easier for others to open your project rather than having to create the files individually.

      Anyway, I did manually compile your code and got a ton of errors, now this could be because I compiled manually and made a mistake or two in doing so.

      Having said the above, there maybe someone here on the forum with far more experience than myself and might spot your mistake/s, but honestly, put your code on Github for ease of access by others.

      Don't just sit there standing around, pick up a shovel and sweep up!

      I live by the sea, not in it.

      D 1 Reply Last reply
      1
      • D diuneiguohai

        Thanks for reading. I am very new to qml.
        It outputs nothing even the ui even when i comment out the whole testingtext.h!!
        I do not know what happened. here is my code

        .pro

        QT += quick
        QT += qml
        CONFIG += c++11
        CONFIG += qmltypes
        QML_IMPORT_NAME = Charts
        QML_IMPORT_MAJOR_VERSION = 1
        
        # You can make your code fail to compile if it uses deprecated APIs.
        # In order to do so, uncomment the following line.
        #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
        
        SOURCES += \
                main.cpp \
                testingtext.cpp
        
        RESOURCES += qml.qrc
        
        TRANSLATIONS += \
            kpp_main_system_yue_HK.ts
        
        # Additional import path used to resolve QML modules in Qt Creator's code model
        QML_IMPORT_PATH =
        
        # Additional import path used to resolve QML modules just for Qt Quick Designer
        QML_DESIGNER_IMPORT_PATH =
        
        # Default rules for deployment.
        qnx: target.path = /tmp/$${TARGET}/bin
        else: unix:!android: target.path = /opt/$${TARGET}/bin
        !isEmpty(target.path): INSTALLS += target
        
        HEADERS += \
            testingtext.h
        
        

        main.cpp

        #include <QGuiApplication>
        #include <QQmlApplicationEngine>
        #include <QDebug>
        #include <QQmlContext>
        #include "testingtext.h"
        
        int main(int argc, char *argv[])
        {
            QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
            QGuiApplication app(argc, argv);
        
            qmlRegisterType<testingtext>("testingtext", 1, 0, "Testingtext");
        
            QQmlApplicationEngine engine;
        
            const QUrl url(QStringLiteral("qrc:/main.qml"));
            QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                             &app, [url](QObject *obj, const QUrl &objUrl) {
                if (!obj && url == objUrl)
                    QCoreApplication::exit(-1);
            }, Qt::QueuedConnection);
            engine.load(url);
        
            return app.exec();
        }
        
        

        textingtext.h

        #include <QtQuick/QQuickPaintedItem>
        #include <QString>
        #include <QColor>
        #include <QObject>
        
        class testingtext : public QObject
        {
            Q_OBJECT
            Q_PROPERTY(QString on9text MEMBER on9text NOTIFY on9textchanged)
            QML_ELEMENT
        
        public:
        
            explicit testingtext(QObject *parent =nullptr);
        
        signals:
            void on9textchanged();
        
        
        private:
            QString text= "on9";
        
        
        
            QString on9text = "";
            void seton9text();
        
        
        };
        
        

        testingtext.cpp

        #include "testingtext.h"
        
        testingtext:: testingtext(QObject *parent): QObject(parent){
        
        }
        
        QString on9text(){
           return "on9";
        }
        
        

        main.qml

        import QtQuick 2.15
        import QtQuick.Controls 2.15
        import testingtext 1.0
        
        Item {
            id: root
            width:1280
            height: 720
            Rectangle {
                id: rectangle1
        
                color: "grey"
                anchors.fill: parent
        
                Testingtext {
                    id: testingtext
                }
        
                RoundButton {
                    id: button2
                    x: 441
                    y: 12
                    width: 200
                    height: 68
                    radius: 8
                    text: qsTr("Button")
                    anchors.left: tab1.right
                    anchors.top: tab1.top
                    anchors.bottom: rectangle.top
                    topPadding: 6
                    anchors.bottomMargin: -6
                    anchors.topMargin: 0
                    anchors.leftMargin: 8
                }
        
                RoundButton {
                    id: button1
                    x: 600
                    y: 12
                    width: 200
                    height: 68
                    radius: 8
                    text: qsTr("Button")
                    anchors.left: tab1.right
                    anchors.top: tab1.top
                    anchors.bottom: rectangle.top
                    topPadding: 6
                    anchors.bottomMargin: -6
                    anchors.topMargin: 0
                    anchors.leftMargin: 8
                }
        
        
                RoundButton {
                    id: button
                    width: 200
                    height: 68
                    radius: 8
                    text: qsTr("Button")
                    anchors.left: button1.right
                    anchors.bottom: rectangle.top
                    anchors.leftMargin: 8
                    anchors.bottomMargin: -8
                    topPadding: 6
                }
        
                Rectangle {
                    id: rectangle
                    color: "#ffffff"
                    radius: 20
                    anchors.top: parent.top
                    anchors.bottom: parent.bottom
                    rotation: 0
                    anchors.rightMargin: 16
                    anchors.leftMargin: 16
                    anchors.bottomMargin: 24
                    anchors.topMargin: 72
                    anchors.horizontalCenterOffset: 4
                    anchors.horizontalCenter: parent.horizontalCenter
        
                    TextInput {
                        id: textInput
                        x: 187
                        y: 288
                        width: 80
                        height: 20
                        text: testingtext.on9text
                        font.pixelSize: 12
                    }
                }
        
                Rectangle {
                    id: tab1
                    width: 200
                    height: 200
                    color: "#ffffff"
                    radius: 8
                    anchors.left: rectangle.left
                    anchors.top: rectangle.top
                    anchors.leftMargin: 0
                    anchors.topMargin: -60
                }
        
        
        
        
            }
        
        
        
        }
        
        

        it is probaly a very dumb mistake that i cant spot!
        Again! thanks for your time reading this!

        ODБOïO Offline
        ODБOïO Offline
        ODБOï
        wrote on last edited by
        #3

        hi
        @diuneiguohai said in It output nothing without error code!!:

        main.qml

        the root item in main.qml must be a Window or ApplicationWindow

        D 1 Reply Last reply
        3
        • MarkkyboyM Markkyboy

          You're not making it easy on yourself or others who may be able to help. Although I'm not sure how to actually do it, you are better off putting your code on Github, making it easier for others to open your project rather than having to create the files individually.

          Anyway, I did manually compile your code and got a ton of errors, now this could be because I compiled manually and made a mistake or two in doing so.

          Having said the above, there maybe someone here on the forum with far more experience than myself and might spot your mistake/s, but honestly, put your code on Github for ease of access by others.

          D Offline
          D Offline
          diuneiguohai
          wrote on last edited by
          #4

          @Markkyboy Thanks for your advice!!! will do next time

          1 Reply Last reply
          0
          • ODБOïO ODБOï

            hi
            @diuneiguohai said in It output nothing without error code!!:

            main.qml

            the root item in main.qml must be a Window or ApplicationWindow

            D Offline
            D Offline
            diuneiguohai
            wrote on last edited by
            #5

            @LeLev Thanks! i changed the root to the applicationwindow type and it still does not output a window.

            ODБOïO 1 Reply Last reply
            0
            • D diuneiguohai

              @LeLev Thanks! i changed the root to the applicationwindow type and it still does not output a window.

              ODБOïO Offline
              ODБOïO Offline
              ODБOï
              wrote on last edited by
              #6

              @diuneiguohai
              did you set visible: true ?

              1 Reply Last reply
              3
              • D Offline
                D Offline
                diuneiguohai
                wrote on last edited by
                #7

                Thank you so much!!! That was a very dumb mistake!!
                I was wondering why people could also output window with root as a item type when i watched tutorial from few years back.
                Is it purely because of the version of QtQuick?

                ODБOïO 1 Reply Last reply
                0
                • D diuneiguohai

                  Thank you so much!!! That was a very dumb mistake!!
                  I was wondering why people could also output window with root as a item type when i watched tutorial from few years back.
                  Is it purely because of the version of QtQuick?

                  ODБOïO Offline
                  ODБOïO Offline
                  ODБOï
                  wrote on last edited by
                  #8

                  @diuneiguohai said in It output nothing without error code!!:

                  I was wondering why people could also output window with root as a item type when i watched tutorial from few years back.

                  i don't know about it. Can you show an example ?

                  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