QWidget
handleHeroChange(int index)
的函数Qcombobox
来调用函数handleHeroChange(int index)
。Qtcreator一直在说:
**QObject::connect: No such slot QWidget::handleHeroChange(int) in ../Testing/Window.cpp:92**
我做错了什么?
代码:
//Window.h
class Window : public QWidget
{
QGraphicsPixmapItem* avatar;
QGraphicsTextItem* heroNameItem;
QGraphicsTextItem* heroStrItem;
QGraphicsTextItem* heroDexItem;
QGraphicsTextItem* herointelItem;
public:
Window(QWidget *parent = 0);
public slots:
void handleHeroChange(int);
};
//Window.cpp
Window::Window(QWidget *parent)
: QWidget(parent)
{
QGridLayout *grid = new QGridLayout(this);
QComboBox *comboHeroClass = new QComboBox();
comboHeroClass->addItem("Witcher");
comboHeroClass->addItem("Maurander");
comboHeroClass->setCurrentIndex(1);
grid->addWidget(comboHeroClass, 2,3,1,1);
QComboBox::connect(comboHeroClass, SIGNAL(currentIndexChanged(int)),this, SLOT(handleHeroChange(int)));
}
void Window::handleHeroChange(int index){
QPixmap myImage;
if(index == 0){
}else if(index == 1){
}
}
答案 0 :(得分:1)
class Window : public QWidget
{
Q_OBJECT
将没有分号的Q_OBJECT宏添加到您的班级并重建您的项目。
如果没有这个宏moc找不到你的课程而且没有创建你的插槽(以及其他一些东西)这就是你收到错误的原因:你看到你的插槽但是它并不存在你得到运行时错误