我在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