测试结果如下:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
//头文件声明信号和槽函数
signals:
void sig_test(int type,double value);
private slots:
void slot_test(int type, double value);
private:
Q_INVOKABLE void fun_test(int type, QString value);
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <QSlider>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
//构造函数关联信号槽
connect(this, SIGNAL(sig_test(int, double)), this, SLOT(slot_test(int, double)));
QMetaObject::invokeMethod(this, "sig_test", Q_ARG(int, 66), Q_ARG(double, 66.66));
QMetaObject::invokeMethod(this, "slot_test", Q_ARG(int, 88), Q_ARG(double, 88.88));
QMetaObject::invokeMethod(this, "fun_test", Q_ARG(int, 99), Q_ARG(QString, "hello"));
emit sig_test(10, 11.1);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::slot_test(int type, double value)
{
qDebug() << type << value;
}
void MainWindow::fun_test(int type, QString value)
{
qDebug() << type << value;
}