///////////////////////Hello_world.cpp
#include<qapplication.h>
#include"my_widget.h"
int main(int argc,char **argv)
{
QApplication a(argc,argv);
my_widget w;
a.setMainWidget(&w);
w.show();
return a.exec();
}
////////////////////////my_widget.cpp
#include<qwidget.h>
#include"my_widget.h"
#include<qpushbutton.h>
#include<qmainwindow.h>
my_widget::my_widget(QWidget *parent,const char *name)
:QWidgetStack(parent,name)
{
one=new QPushButton(parent,"one");
two=new QMainWindow(0,"two",WType_TopLevel);
addWidget(one,1);
addWidget(two,2);
emit aboutToShow(1);
connect(one,SIGNAL(clicked()),this,SLOT(raiseWidget(id(two))));
}
////////////////////////my_widget.h
#ifndef TRACK
#define TRACK
#include<qwidget.h>
#include<qwidgetstack.h>
class QPushButton;
class QMainWindow;
class my_widget:public QWidgetStack
//The first one is a button
//The second one is a picture
//The third one is a splashscreen
//The fourth one is a
{
Q_OBJECT
public:
my_widget(QWidget *parent=0,const char *name="my_widget");
private:
QPushButton *one;
QMainWindow *two;
};
#endif
运行时的出错信息为:
QObject::connection:No Such Slot my_widget::raiseWidget(id(two))
QObject::connection:(sender name: "one")
QObject::connection:(receiver name: "my_widget")
明明my_widget继承了QWidgetStack的slot,为什么说没有呢?