그래서 C++로 Qt 프레임 워크를 배우려고합니다. 나는 신호와 슬롯을 이해하는 중이고 사용자 정의 슬롯을 만드는 데 어려움을 겪고 있습니다. updateMessage() 내 테스트 내부 공공 슬롯로 선언QT C++ - 신호 및 슬롯 : 슬롯 없음 QLabel ... 심지어 클래스 SLOT 함수가 있습니다.
QObject::connect: No such slot QLabel::updateMessage() in main.cpp:28
클래스
다음은 : 나는 몇 가지 튜토리얼을 따라 그래서, 내 프로그램은 다음과 같은 오류와 함께 종료
Test.h
0 : 내 코드에서 일부 조각MAIN.CPP
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Test t;
t.window->setWindowTitle("Testing Qt");
t.window->setLayout(t.layout);
t.window->show();
return app.exec();
}
Test::Test(void)
{
window = new QWidget;
lblMsg = new QLabel;
btnShow = new QPushButton("Show message");
connect(btnShow,SIGNAL(clicked()),lblMsg,SLOT(updateMessage()));
layout = new QGridLayout;
layout->addWidget(lblMsg);
layout->addWidget(btnShow);
char str1[] = "Hello, Qt World!";
setMessage(str1);
}
Test::~Test(void)
{
}
void Test::setMessage(char *tMsg)
{
memcpy(msg, tMsg, sizeof(msg));
}
char* Test::getMessage()
{
return msg;
}
void Test::updateMessage()
{
string strMsg(getMessage());
QString qstr = QString::fromStdString(strMsg);
lblMsg->setText(qstr);
delete msg;
}
HelloQtWorld.pro는
######################################################################
# Automatically generated by qmake (3.0) Tue Nov 15 00:30:22 2016
######################################################################
TEMPLATE = app
TARGET = HelloQtWorld
INCLUDEPATH += .
# Input
HEADERS += stdafx.h Test.h
SOURCES += anotherClass.cpp \
main.cpp \
stdafx.cpp \
GeneratedFiles/qrc_helloqtworld.cpp
RESOURCES += helloqtworld.qrc
또한 누군가가 신호 및 슬롯이 작동하는 방법을 나에게 설명하려고 수 있습니까? 미리 감사드립니다. :)
안녕하세요. 답변 감사합니다.이제 작동 중입니다. 또한 신호 및 슬롯에 대한 참고 자료를 공유해 주셔서 감사합니다. 감사합니다. 고맙습니다. :) –
@ZMars 오신 것을 환영합니다. – demonplus