[英]Qt no such signal, but it does exist
Qt無法看到存在的信號。
我有一個主窗口打開一個子窗口,並且該連接的語句運行正常:
主窗口
#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(Person&,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
似乎不使用代碼自動完成功能可能是答案的一部分,因為我必須手動輸入信號
connect(editStaffWin, SIGNAL(sendPerson(Person &, int)), this, SLOT(receiveEditedPerson(Person&,int)));
運行干凈,qmake,構建所有內容也可能是其中的一部分。 可能還引起問題的是我如何為connect語句編寫信號,但回頭看,它是相同的。
但是,我所做的是從sendPerson信號中刪除了int聲明,清理,構建,然后將它們放回原位,並且成功了。
除此之外,我不確定是什么原因導致它無法正常工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.