• 6166阅读
  • 2回复

[提问]QComboBox信号槽的问题 [复制链接]

上一主题 下一主题
离线野比大雄
 
只看楼主 倒序阅读 楼主  发表于: 2011-08-21
从网上下载了一个小程序测试QComboBox信号槽

#include <QApplication>
#include <QPushButton>
#include <QComboBox>
#include <QLabel>
#include <QVBoxLayout>
#include <QWidget>
#include <QString>
void print2Screen(){
  printf("changed\n");
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget *win =new QWidget;
QVBoxLayout *layout = new QVBoxLayout;
QComboBox *combo = new QComboBox();
QLabel *label = new QLabel("hello");
QPushButton *helloButton = new QPushButton("Show Label");
combo->addItem("A");
combo->addItem("B");
combo->addItem("C");
QObject::connect(combo, SIGNAL(activated(int)),label, SLOT(hide()));
QObject::connect(combo, SIGNAL(currentIndexChanged(int)),label, SLOT(print2Screen()));
QObject::connect(helloButton, SIGNAL(clicked()),label, SLOT(show()));
layout->addWidget(label);
layout->addWidget(combo);
layout->addWidget(helloButton);

win->setLayout(layout);
win->showMaximized();
return app.exec();
}

运行时报错:QObject::connect: No such slot QLabel::print2Screen()

哪位帮忙看看什么问题
谢谢!
离线野比大雄
只看该作者 1楼 发表于: 2011-08-21
已经解决
忘了声明SLOTS
离线copyleft_x
只看该作者 2楼 发表于: 2011-08-21
原因:报错信息已经说的很清楚了,而且print2Screen()压根就不是槽函数,LZ还是先补补基础知识吧。
快速回复
限100 字节
 
上一个 下一个