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. Problems with QQmlViewer
Forum Update on Monday, May 27th 2025

Problems with QQmlViewer

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 2 Posters 908 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.
  • BlasterB Offline
    BlasterB Offline
    Blaster
    wrote on last edited by
    #1

    ello, I'm working on an application in QML for android, so I'm using the QQmlViewer to make use of the data types created by me, but I have a problem: when the application starts, I have to press the back button to be able to trigger the different components of my application. How can i fix this?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Without any code to analyse, it's going to be pretty difficult to help you.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • BlasterB Offline
        BlasterB Offline
        Blaster
        wrote on last edited by
        #3

        Sorry about that, Here is the code:

        int main(int argc, char *argv[])
        {
            QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
            QApplication app(argc, argv);
            QQuickView viewer;
            viewer.setResizeMode(QQuickView::SizeRootObjectToView);
        
            SomeName somename;
        
            QQuickStyle::setStyle("Material");
        
            QQmlContext *context = viewer.rootContext();
        
            context->setContextProperty("SomeName", &somename);
        
            QObject::connect(viewer.engine(), &QQmlEngine::quit, &viewer, &QWindow::close);
            viewer.setSource(QUrl("qrc:/main.qml"));
        
            viewer.show();
        
            return app.exec();
        
        }
        
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          What do you have in your QML file ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • BlasterB Offline
            BlasterB Offline
            Blaster
            wrote on last edited by
            #5

            This is all the code in my mail.qml file:

            import QtQuick 2.6
            import QtQuick.Controls 2.0
            import QtQuick.Layouts 1.0
            import Qt.labs.settings 1.0
            import QtQuick.Controls.Material 2.0
            import QtQuick.LocalStorage 2.0
            
            ApplicationWindow {
                id: appwindow
                visible: true
                width: 340
                height: 480
                title: qsTr("RegCharge")
            
            
                Settings{
                    id: settings
                    property string style: "Material"
                }
            
                Loader{
                    id: splashLoader
                    anchors.fill: parent
                    source: "qrc:/SplashScreen.qml"
                }
            
                header: ToolBar{
                    Material.foreground: "white"
                    Material.background: Material.Blue
                    RowLayout{
                        spacing: 20
                        anchors.fill: parent
            
            
                        ToolButton{
                            id: hamButton
                            contentItem: Image{
                                fillMode: Image.Pad
                                horizontalAlignment: Image.AlignHCenter
                                verticalAlignment: Image.AlignVCenter
                                source: "qrc:/Images/drawer.png"
                            }
                            onClicked: drawer.open()
                        }
            
                        Label{
                            id: titleLabel
                            text: "RegCharge"
                            font.pixelSize: 20
                            elide: Label.ElideRight
                            horizontalAlignment: Qt.AlignHCenter
                            verticalAlignment: Qt.AlignVCenter
                            Layout.fillWidth: true
                        }
            
                        ToolButton{
                            id: dotsButton
                            contentItem: Image{
                                fillMode: Image.Pad
                                horizontalAlignment: Image.AlignHCenter
                                verticalAlignment: Image.AlignVCenter
                                source: "qrc:/Images/menu.png"
                            }
                            onClicked: optionsMenu.open()
            
                            Menu{
                                id: optionsMenu
                                x: parent.width - width
                                transformOrigin: Menu.TopRight
            
                                MenuItem{
                                    text: "About"
                                    onTriggered: {
                                        listView.currentIndex = listView.count - 1
                                        titleLabel.text = "Acerca de"
                                        stackView.replace("qrc:/About.qml")
                                    }
                                }
                            }
                        }
                    }
                }
            
            
                Drawer{
                    id: drawer
                    width: Math.min(appwindow.width, appwindow.height) / 3 * 2
                    height: appwindow.height
            
            
                    ListView{
                        id: listView
                        currentIndex: 0
                        anchors.fill: parent
            
                        delegate: ItemDelegate {
                            width: parent.width
                            text: model.title
                            highlighted: ListView.isCurrentItem
                            onClicked: {
                                if(listView.currentIndex != index){
                                    listView.currentIndex = index
                                    titleLabel.text = model.title
                                    stackView.replace(model.source)
                                }
                                drawer.close()
                            }
                        }
            
                        model: ListModel{
                            id: listModel
                            ListElement {title: "Principal"; source: "qrc:/Principal.qml" }
                            ListElement {title: "DataBase"; source: "qrc:/DataBase.qml" }
                            ListElement {title: "Estadística"; source: "qrc:/Statistic.qml" }
                            ListElement {title: "Costos"; source: "qrc:/Costs.qml" }
                            ListElement {title: "Acerca de"; source: "qrc:/About.qml"  }
                        }
                    }
                }
            
                StackView{
                    id: stackView
                    anchors.fill: parent
                    
                    ToolTip {
                        id: toolTip
                        timeout: 3000
                        visible: Keys.onBackPressed()
                        text: "Presione nuevamente para salir"
                        Keys.onBackPressed:
                        {
                            Qt.quit()
                        }
                    }
            
                    initialItem: Principal{}
                    Component.onCompleted: {
                        splashLoader.visible = false
                    }
                    Keys.onEscapePressed: console.log("Escape")
                }
            
                function createCostsTable() {
                    var db = LocalStorage.openDatabaseSync("RegStore", "1.0", "RegStore Database", 5242880);
            
                    db.transaction(
                                function(tx) {
                                    tx.executeSql('CREATE TABLE IF NOT EXISTS Costs(Type integer, Valor double)');
            
                                    var rs = tx.executeSql('SELECT * FROM Costs');
            
                                    if(rs.rows.length <= 0)
                                    {
                                        var arr = [3, 5, 11, 14, 17, 22, 27]
                                        var ar2 = [2.8, 4.8, 10, 13, 16.5, 20.8, 25.8]
            
                                        for(var i = 0; i < arr.length; i++)
                                        {
                                            tx.executeSql('INSERT INTO Costs VALUES(?,?)', [arr[i], ar2[i]])
                                        }
                                        console.log("Correcto")
                                    }
                                }
                                )
                }
            
                Component.onCompleted: createCostsTable()
            }
            
            
            1 Reply Last reply
            0
            • BlasterB Offline
              BlasterB Offline
              Blaster
              wrote on last edited by
              #6

              People, I solved the problem myself, although I really do not know what happens with QQmlViewer. In the end I used QQmlApplicationEngine , so the code was like this:

              int main(int argc, char *argv[])
              {
                  QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
                  QGuiApplication app(argc, argv);
              
                  QQuickStyle::setStyle("Material");
                  
                  BackEnd backend;
              
                  QQmlApplicationEngine engine;
                  engine.rootContext()->setContextProperty("backEnd", &backend);
                  engine.load(QUrl(QLatin1String("qrc:/main.qml")));
              
                  return app.exec();
              }
              
              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