Quantcast
Channel: Qt DevNet forums: Qt Quick 1283365070**
Viewing all articles
Browse latest Browse all 4972

Trouble with calling a cpp method from qml

$
0
0
Hi every body, Actually I’m having trouble with merging both qml and c++ .My little application contains two pages at the moment and my problem is: In the first page (main.qml) whan I created an Item class that contains all the widgets of my window nothing is displayed when I run the program. I will be grateful if someone helps me to solve this problem. main.cpp #include "enter.h" #include <QUrl> #include <QQuickView> #include <QApplication> #include <QQmlComponent> #include <QQmlEngine> #include <QObject> #include <QQuickWindow>   int main(int argc, char *argv[]) {     QApplication app(argc, argv);       qmlRegisterType<enter>("appEntrance", 1, 0, "appEntrance");     qmlRegisterType<HomePage>("home",1,0,"home");       QQuickView view;     view.setSource(QUrl::fromLocalFile("qrc:///main.qml"));     view.show();     return app.exec(); } enter.h #ifndef ENTER_H #define ENTER_H   #include <QWidget> #include "home.h" class enter :public QWidget {     Q_OBJECT   public:     Q_INVOKABLE void openHomePage();   };   #endif // ENTER_H enter.cpp #include "home.h" #include "enter.h"   void enter::openHomePage() {     HomePage w1;        w1.show();     } home.h #ifndef HOME_H #define HOME_H   #include <QWidget> class HomePage : public QWidget {     //I havent defined the any method yet };   #endif // HOME_H main.qml import QtQuick 2.2 import QtQuick.Controls 1.1 import QtQuick.Controls.Styles 1.1 import QtQuick.Layouts 1.1     Item {     id:fenetrePrincipale     enter{         id:appEntrance     Rectangle {         color: "#fbf79a"         ColumnLayout{              id:conteneur              anchors.fill:parent             ColumnLayout {                 Layout.alignment:Qt.AlignCenter                 id: columnLayout1                 spacing: 60                 Image {                     id: image1                     width: 6                     height: 0                     Layout.alignment: Qt.AlignCenter                     source: "windows8-1-food.jpg"                 }                   Button {                     Layout.alignment: Qt.AlignCenter                     width: 200                     height: 100                     text: "Entrer"                     style: ButtonStyle {                         background: Rectangle {                             implicitWidth: 100                             implicitHeight: 25                             border.width: control.activeFocus ? 2 : 1                             border.color: "#888"                             radius: 14                             gradient: Gradient {                                 GradientStop { position: 0 ; color: control.pressed ? "#ccc" : "#f4d76f" }                                 GradientStop { position: 1 ; color: control.pressed ? "#aaa" : "#ddb936" }                             }                         }                     }                     clicked: appEntrance.openHomePage()                 }                     }             } } } } home.qml import QtQuick 2.2 import QtQuick.Controls 1.1 import QtQuick.Controls.Styles 1.1 import QtQuick.Layouts 1.1       Item {     HomePage{         id:home         ColumnLayout {             spacing:60             anchors.fill:parent             Button {                 id: acceuil                 Layout.alignment: Qt.AlignVCenter                 width: 167                 height: 28                 text: qsTr("button1")                 activeFocusOnPress: false             }               Button {                 id: candidats                 Layout.alignment: Qt.AlignVCenter                 width: 167                 height: 28                 text: qsTr("button2")             }               Button {                 id: interimaires                 Layout.alignment: Qt.AlignVCenter                 width: 167                 height: 28                 text: qsTr("button3")             }               Button {                 id: entreprises                 Layout.alignment: Qt.AlignVCenter                 width: 167                 height: 28                 text: qsTr("button4")             }               Button {                 id: aPropos                 Layout.alignment: Qt.AlignVCenter                 width: 167                 height: 28                 text: qsTr("button 5")             }           }       } }

Viewing all articles
Browse latest Browse all 4972

Trending Articles