繁体   English   中英

Qt没有这样的信号,但是它确实存在

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM