【发布时间】:2014-11-08 11:56:23
【问题描述】:
我是 Qt 的新手,我想将 qml 日历信号 clicked(date date) 连接到 cpp slote,如下所示: 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
}
}
}
}
}
}
日历.h:
class MyCalendar : public QObject
{
Q_OBJECT
public:
MyCalendar();
public slots:
void ShowShedulerWindow() const;
};
日历.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::connect: 没有这样的信号 Calendar_QMLTYPE_14::clicked(QDate) in ..\Economist\main.cpp:24 QObject::connect: (发件人姓名: '日历') 请告诉我做错了什么?
【问题讨论】:
标签: c++ qt user-interface