2014-11-22 60 views
0

Qt无法看到存在的信号。Qt没有这样的信号,但它确实存在

我打开了一个子窗口一个主窗口,并且该连接语句的工作绝对没问题:

mainwindow.h

#ifndef MAINWINDOW_H 
#define MAINWINDOW_H 

#include <QMainWindow> 
#include "addstaffform.h" 
#include "stafflist.h" 
#include "editstaffwindow.h" 
#include <QDialog> 
#include <QString> 
#include <QList> 
#include "person.h" 

namespace Ui { 
class MainWindow; 
} 

class MainWindow : public QMainWindow 
{ 
    Q_OBJECT 

public: 
    explicit MainWindow(QWidget *parent = 0); 
    ~MainWindow(); 

private slots: 
    void on_btn_add_clicked(); 
    void refreshStaffList(); 

    void receiveData(Person& newPerson); 
    void receiveEditedPerson(Person &editedPerson, int index); 

    void updateDeleteEnabled(); 
    void updateEditEnabled(); 
    void on_btn_delete_staff_clicked(); 

    void on_btn_staff_edit_clicked(); 


private: 
    Ui::MainWindow *ui; 
    QString s; 
    QMainWindow *newWin; 
    QMainWindow *editStaffWin; 
    StaffList *m_staffList; 
    QList<Person> m_personList; 
    Person m_person; 

}; 

#endif // MAINWINDOW_H 

在mainwindow.cpp的方法,与没有工作问题:

void MainWindow::on_btn_add_clicked() 
{ 
    //Open the add staff window, which is a form 
    newWin = new AddStaffWindow(this); 
    //connect the signal from the new form to the slot in this window to receive the person object 
    connect(newWin, SIGNAL(sendData(Person&)), this, SLOT(receiveData(Person&))); 
    newWin->show(); 
} 

信号在addstaffwindow.h(为newwin的实例化)

signals: 
    void sendData(Person &p); 

现在,在编辑窗体(editStaffWin)中,我有信号,并且确定Q_OBJECT肯定存在,清理,运行QMake并构建好几次,但它不认为信号存在。

editstaffwindow.h

signals: 
    void sendPerson(Person &, int index); 
在mainwindow.cpp编辑

所以,sendPerson(人&,INT)显示不出来:

void MainWindow::on_btn_staff_edit_clicked() 
{ 
    //Get the index of the widget 
    int index = ui->lst_staff->currentRow(); 
    int size = ui->lst_staff->count(); 

    if (index > -1 && index <= size) 
    { 
     //get from staff list 
     m_person = m_staffList->getStaffAt(index); 
     editStaffWin = new EditStaffWindow(this, m_person, index); 

     connect(editStaffWin, SIGNAL(sendPerson(Person &, int)), this, SLOT(receiveEditedPerson(Person&,int))); 

     editStaffWin->show(); 
    } 

} 

任何想法,为什么?我没有为他们做任何不同的事情。

编辑:全EditStaffWindow头:

#ifndef EDITSTAFFWINDOW_H 
#define EDITSTAFFWINDOW_H 

#include <QMainWindow> 
#include "mainwindow.h" 
#include "person.h" 
#include <QObject> 

namespace Ui { 
class EditStaffWindow; 
} 

class EditStaffWindow : public QMainWindow 
{ 
    Q_OBJECT 

public: 
    explicit EditStaffWindow(QWidget *parent, Person &p, int index); 
    ~EditStaffWindow(); 

signals: 
    void sendPerson(Person &, int index); 

private: 
    Ui::EditStaffWindow *ui; 
    Person m_person; 
    int m_index; 

public slots: 
    void showData(Person &p, int index); 

private slots: 
    void on_btn_save_clicked(); 
    void on_btn_cancel_clicked(); 

}; 

#endif // EDITSTAFFWINDOW_H 
+0

您使用的是哪个版本的Qt?如果是5,尝试新的连接语法,它会给你编译时错误。 – dtech 2014-11-22 15:25:09

+0

什么是确切的错误信息?你也可以显示EditStaffWindow头吗? – BartoszKP 2014-11-22 15:27:39

+0

尝试过(我使用5.3),但没有建议&editStaffWin ::。它看不到有任何信号存在,对于editStaffWin – 2014-11-22 15:28:44

回答

0

看来,不使用代码自动填充功能可能是答案的一部分,我必须手动输入信号

connect(editStaffWin, SIGNAL(sendPerson(Person &, int)), this, SLOT(receiveEditedPerson(Person&,int))); 

运行干净, qmake,构建所有可能也是它的一部分。也可能导致问题的是我是如何为连接语句写信号的,但回过头来看,情况也是如此。

但是我所做的是从sendPerson信号中删除int声明,clean,build,然后放回它,并且它工作。

除此之外,我不确定是什么导致它不起作用。