Bonjour,
Je tente d'écrire un pavé numérique en c++/QML. Je sèche sur l'erreur suivante :
Quelqu'un aurait-il une idée d'où elle pourrait provenir ?!
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 ..\paveNum\main.cpp: In function 'int qMain(int, char**)': ..\paveNum\main.cpp:17: error: no matching function for call to 'QObject::connect(QGraphicsObject**, const char*, MyClass**, const char*)' c:\QtSDK\Simulator\Qt\mingw\include/QtCore/qobject.h:198: note: candidates are: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType) c:\QtSDK\Simulator\Qt\mingw\include/QtCore/qobject.h:313: note: bool QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
Voici les différents fichiers:
.h
.cpp
Code C++ : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 #include <QObject> #ifndef MYCLASS_H #define MYCLASS_H class MyClass : QObject { Q_OBJECT public: MyClass(); public slots: void cppSlot(QString msg); }; #endif // MYCLASS_H
main.cpp
Code C++ : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 #include <MyClass.h> #include <QDebug> MyClass::MyClass(){} void MyClass::cppSlot(QString msg){ qDebug()<<"Resultat : "<<msg; }
touche.qml
Code C++ : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 #include <QtGui/QApplication> #include "qmlapplicationviewer.h" #include <QObject> #include <QDeclarativeView> #include <MyClass.h> int main(int argc, char *argv[]) { QApplication app(argc, argv); QDeclarativeView view; view.setSource(QUrl::fromLocalFile("qml/paveNum/main.qml")); MyClass *myClass = new MyClass; QGraphicsObject *item = view.rootObject(); QObject::connect(&item, SIGNAL(qmlResult(QString)),&myClass, SLOT(cppSlot(QString))); view.show(); return app.exec(); }
main.qml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 import QtQuick 1.0 Item { id: container property alias toucheTxt: label.text signal clicked width: 70 height: 70 Rectangle { id: rectangle color: "white" border.color: "grey" border.width: 1 radius: 5 anchors.fill: parent } Text { id: label anchors.centerIn: parent } MouseArea { id: mousearea anchors.fill: parent onClicked: container.clicked() } states:[State { when: mousearea.pressed PropertyChanges { target:rectangle; color: "lightblue"} } ] }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85 import QtQuick 1.0 Rectangle { id: pave_num width: grid.width+10 height: grid.height+80 color: "lightgrey" signal qmlResult(string res) Grid { id: grid spacing: 5 columns: 3 anchors.centerIn: parent Repeater { model: 9 Touche { toucheTxt: 9-index onClicked: aff.setText(toucheTxt) } } Touche { toucheTxt: "0" onClicked: aff.setText(toucheTxt) } Touche { toucheTxt: "C" onClicked: aff.clear() } Touche { toucheTxt:"Ok" onClicked: aff.valid() } } Rectangle{ border.color : "grey" anchors.top : parent.top anchors.topMargin : 5 anchors.horizontalCenter: parent.horizontalCenter id : recF width : grid.width color : "#FFF"; height : 30 radius : 2 //opacity : 0.7; TextInput{ id : aff anchors.left :parent.left anchors.leftMargin : 5 anchors.top : parent.top anchors.topMargin : 5 width : parent.width - 10 font.pointSize: 13 function setText(texte){ aff.text += texte } function getText(){ return aff.text } function clear(){ console.log("clear") aff.text = "" } function valid(){ console.log(aff.getText()) qmlResult(aff.getText()) } } } Text { text: "Test pavé numérique" font.italic: true anchors.bottom: parent.bottom anchors.bottomMargin: 5 anchors.left: parent.left anchors.leftMargin: 5 font.pixelSize: 12 } }
Partager