Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

It output nothing without error code!!



  • 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!



  • 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.



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

    main.qml

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



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



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



  • @diuneiguohai
    did you set visible: true ?



  • 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?



  • @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 ?


Log in to reply