主窗口:QtGuiApplication1
QtGuiApplication1.h
#pragma once
#include <QtWidgets/QMainWindow>
#include "ui_QtGuiApplication1.h"
class QtGuiApplication1 : public QMainWindow
{
Q_OBJECT
public:
QtGuiApplication1(QWidget *parent = Q_NULLPTR);
public slots:
void on_SaleButton_clicked();
void Receive(int);
private:
Ui::QtGuiApplication1Class ui;
};
QtGuiApplication1.cpp
#include "QtGuiApplication1.h"
#include "Sale.h"
#include <qmessagebox.h>
QtGuiApplication1::QtGuiApplication1(QWidget* parent)
: QMainWindow(parent)
{
ui.setupUi(this);
}
void QtGuiApplication1::on_SaleButton_clicked()//跳转到收银模块
{
auto sale=new Sale();
connect(sale, SIGNAL(Send(int)), this, SLOT(Receive(int)));//连接槽函数
sale->show();
}
void QtGuiApplication1::Receive(int a)
{
QMessageBox messageBox(QMessageBox::Information, "提示","创建了子窗口", QMessageBox::Yes, NULL);
}
子窗口Sale
Sale.h
#pragma once
#include "ui_Sale.h"
#include <QtWidgets/QMainWindow>
class Sale : public QMainWindow
{
Q_OBJECT
public:
Sale(QWidget* parent = Q_NULLPTR);
signals:
void Send(int);
private:
Ui::Sale ui;
};
Sale.cpp
#include "Sale.h"
Sale::Sale(QWidget* parent ):QMainWindow(parent)
{
ui.setupUi(this);
emit Send(1);
}
我的想法是点击主窗体的SaleButton按钮显示子窗口,同时主窗口弹出对话框,但是能显示子窗口,并没有弹出对话框,槽函数是无效的