Qt没有这样的信号,但它确实存在
Qt no such signal, but it does exist
Qt 看不到存在的信号。
我有一个打开子窗口的主窗口,其连接语句工作正常:
主窗口.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
主窗口中的方法.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并构建几次,但它认为信号不存在。
编辑员工窗口.h
signals:
void sendPerson(Person &, int index);
所以在主窗口中.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();
}
}
知道为什么吗?我没有为他们中的任何一个做任何不同的事情。
编辑:完整的编辑人员窗口标题:
#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 声明,清理、构建,然后将它们放回原处,它奏效了。
除此之外,我不确定是什么原因导致它不起作用。
相关文章:
- C++模板来检查友元函数的存在
- Qt VTK交互风格的信号到小部件
- 获取日期异步信号安全吗?如果在信号处理程序中使用,它会导致死锁吗
- 既然存在危险,为什么项目要使用-I include开关
- 我们可以访问一个不存在的联盟的成员吗
- C++:对不存在的命名空间使用命名空间指令
- 如何将点击的信号和插槽添加到qt中的自定义按钮中
- 如何在没有信号的情况下从C++执行QML插槽
- C++quit()函数中可能存在作用域问题
- C++擦除(如果存在)
- 线程之间的布尔停止信号
- g++ 说函数不存在,即使包含正确的标头
- 当存在新的串行端口时信号
- 为什么这会过早地存在于西吉尔信号中
- Qt没有这样的信号,但它确实存在
- 是否存在串行化boost::signals2信号调用的现有方法
- 绘制或渲染QGraphicsView或QWidget时是否存在信号或事件
- 是否存在具有基本反射的轻量级信号槽实现
- QT C++ - 信号和插槽:"No such slot QLabel..."甚至插槽功能也存在于我的类中
- Qt5中存在哪些同步原语,允许我在单个线程中等待信号到达