2013-01-13 42 views
0

我有這樣一段代碼:QT沒有這種槽

przystanki.h

#ifndef PRZYSTANKI_H 
#define PRZYSTANKI_H 
#include "component.h" 
class Przystanki : public Component 
{ 
public: 
    Przystanki(QWidget *parent = 0); 

signals: 
    void deletePosition(QString); 
public slots: 
    void deleteListItem(); 
    void addListItem(QString label); 
    void createListItem(QString label, DodajPrzystanek* elem); 

}; 

#endif // PRZYSTANKI_H 

component.h

#ifndef COMPONENT_H 
#define COMPONENT_H 
#include <QListWidget> 
#include <QGroupBox> 
#include "dodajprzystanek.h" 
class Component : public QGroupBox 
{ 
    Q_OBJECT 
public: 
    explicit Component(QString name, QWidget *parent = 0); 
    QListWidget* list; 

}; 

#endif // COMPONENT_H 

片段,它使用它:

MyWindow::MyWindow(QWidget *parent) : 
QMainWindow(parent) 
{ 
webView = new MyWebView(this); 
mainlayout = new QGridLayout(); 
mainlayout->addWidget(webView, 0,0); 
Przystanki *stop = new Przystanki(this); 
mainlayout->addWidget(stop, 0, 1); 
QHBoxLayout* bottom = new QHBoxLayout(); 
//bottom->addWidget(new QLabel("Linie")); 
bottom->addWidget(new Component("Autobusy")); 
bottom->addWidget(new Component("Linie")); 
QHBoxLayout* hrightCorner = new QHBoxLayout(); 
QVBoxLayout* rightCorner = new QVBoxLayout(); 
rightCorner->addStretch(1); 
rightCorner->addWidget(new QPushButton("Start", this)); 
//QLabel* label = new QLabel("Labelka"); 

//rightCorner->addWidget(label); 
rightCorner->addStretch(1); 
hrightCorner->addLayout(rightCorner); 
mainlayout->addLayout(bottom, 1, 0); 
mainlayout->addLayout(hrightCorner, 1, 1); 
hrightCorner->setAlignment(Qt::AlignCenter); 
this->setCentralWidget(new QWidget); 
this->centralWidget()->setLayout(mainlayout); 
connect(webView, SIGNAL(getMapPosition(QString)), stop, SLOT(addListItem(QString))); 
connect(stop, SIGNAL(deletePosition(QString)), webView, SLOT(deleteMarker(QString))); 


} 

我得到的是:

loaded the Generic plugin 
Object::connect: No such slot Component::addListItem(QString) 
Object::connect: No such signal Component::deletePosition(QString) 

它將插槽和信號的定義從組件移到它的派生類Przystanki後發生。我已經刪除了整個構建目錄,運行乾淨,運行qmake並再次構建一次,並沒有幫助。任何人都可以向我解釋我做錯了什麼?

+2

我在這段代碼中看不到任何相關的'connect'調用。此外,應該有文件名和行,連接發生在哪裏。 –

+0

我編輯了這個問題。我刪除了一些沒有插槽的第一行,因爲在這種情況下插槽真的沒有了。 –

回答

2

您的類Przystanki缺少Q_OBJECT宏。添加它,將przystanki.h添加到.pro文件中的HEADERS(如果還沒有),然後重新運行qmake。

+0

我試過這樣做,但後來我得到了鏈接器錯誤,我不明白。錯誤是:未定義的參考'vtable爲Przystanki' –

+0

@WojciechReszelewski,這意味着,您的* .moc不鏈接到。可能你的構建系統有一些問題。 –

+0

我已經刪除了整個構建目錄,乾淨,運行qmake並再次構建,它工作。非常感謝。 –

相關問題