我在Qt的新的,我想連接QML日曆信號點擊(日期爲準),以CPP斯魯特這樣的: main.qml:不能獲得點擊(日期日期)信號從日曆
ApplicationWindow {
title: qsTr("MoneyInTheBank")
visible: true
width: 335
height: 500
color: "#333"
Item{
x: 5
y: 9
width: 325
height: 240
Calendar{
id: calendar
objectName: "calendar"
x: 4
y: 5
width: 318
height: 230
weekNumbersVisible: true
style: CalendarStyle {
gridVisible: false
dayDelegate: Rectangle {
gradient: Gradient {
GradientStop {
position: 0.00
color: styleData.selected ? "#111" : (styleData.visibleMonth && styleData.valid ? "#444" : "#666");
}
GradientStop {
position: 1.00
color: styleData.selected ? "#444" : (styleData.visibleMonth && styleData.valid ? "#111" : "#666");
}
GradientStop {
position: 1.00
color: styleData.selected ? "#777" : (styleData.visibleMonth && styleData.valid ? "#111" : "#666");
}
}
Label {
text: styleData.date.getDate()
anchors.centerIn: parent
color: styleData.valid ? "white" : "grey"
}
Rectangle {
width: parent.width
height: 1
color: "#555"
anchors.bottom: parent.bottom
}
Rectangle {
width: 1
height: parent.height
color: "#555"
anchors.right: parent.right
}
}
}
}
}
}
Calendar.h:
class MyCalendar : public QObject
{
Q_OBJECT
public:
MyCalendar();
public slots:
void ShowShedulerWindow() const;
};
Calendar.cpp
MyCalendar::MyCalendar()
{
}
void MyCalendar::ShowShedulerWindow() const
{
QMessageBox msgBox;
msgBox.setText("Button pushed");
msgBox.exec();
}
的main.cpp
#include "Calendar.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QQmlApplicationEngine engine;
QQmlComponent qComponent(&engine,
QUrl(QStringLiteral("qrc:/main.qml")));
QObject *qObject = qComponent.create();
QObject *qobjCalendar = qObject->findChild<QObject*>("calendar");
if(qobjCalendar)
{
MyCalendar *objCalendar = new MyCalendar();
QObject::connect(qobjCalendar, SIGNAL(clicked(QDate)), objCalendar, SLOT(ShowShedulerWindow()));
}
return app.exec();
}
而且我有: 的QObject ::連接:沒有這樣的信號Calendar_QMLTYPE_14 ::點擊(QDATE)在.. \經濟學家\ main.cpp中:24 的QObject ::連接:(發件人名稱: '日曆' ) 請告訴我做錯了什麼?
非常感謝您! – otashlanov 2014-11-08 12:27:53
它看起來像文檔仍然是錯誤的(Qt 5.6)。根據文檔[1]日期(QML)映射到QDate(C++)。但是這是不正確的,並且不起作用,正如Mitch已經提到的那樣。 [1] http://doc.qt.io/qt-5/qtqml-cppintegration-data.html – user2494129 2016-05-24 19:05:27