1. 程式人生 > >Object::connect: No such slot (QT槽丟失問題)

Object::connect: No such slot (QT槽丟失問題)

1、看看你的類宣告中有沒有Q_OBJECT,並繼承public QMainWindow{

    例如:       

class CPlot: public QMainWindow{
	Q_OBJECT

2、你宣告的函式要加宣告:

      private slots:

         void xxxx();

 並且要把上面一段函式新增到建構函式的下面,被建構函式直接訪問:

 public:
    CPlot(QWidget *parent = 0);
    private slots:
        void openFile();
        void segmentObj();
        void capture();
        void drawRays();   

3、檢查槽函式名拼寫是否有誤,以及對應的signal和slot的引數是否一致

       如果還不行的話,清理專案,刪掉原有的moc_xxx.cpp,重新執行qmake.

或者自己修改一下:

      例如:新增槽:

static const char qt_meta_stringdata_OpenGLViewer[] = {
	"MainViewer\0\0openFile()\0segmentObj()\0"
	"capture()\0"
};
void CPlot::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
{
	if (_c == QMetaObject::InvokeMetaMethod) {
		Q_ASSERT(staticMetaObject.cast(_o));
		CPlot *_t = static_cast<CPlot *>(_o);
		switch (_id) {
		case 0: _t->openFile(); break;
		case 1: _t->segmentObj(); break;
		case 2: _t->capture(); break;
		default: ;
		}
	}
	Q_UNUSED(_a);
}