////////////////////// Файл x.h //////////////////////
#ifndef X_H
#define X_H
#include <QtDebug>
class X : public QObject
{
Q_OBJECT
public:
X(QObject *parent = 0);
public slots:
void exampleSlot(QList<int> list);
signals:
void exampleSignal(QList<int> list);
};
#endif // X_H
////////////////////// Файл x.cpp //////////////////////
#include"x.h"
X::X(QObject *parent)
: QObject(parent)
{
QList<int> list;
list.append(1);
qDebug() << "value before slot: " << list;
connect(this, SIGNAL(exampleSignal(QList<int>)), this, SLOT(exampleSlot(QList<int>)));
emit exampleSignal(list);
qDebug() << "value after slot: " << list;
}
void X::exampleSlot(QList<int> list) {
list.append(2);
qDebug() << "value in slot: " << list;
}
////////////////////// Файл main.cpp //////////////////////
#include <QApplication>
#include "x.cpp"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
X x;
return app.exec();
}
////////////////////// Вывод //////////////////////
Запуск...
value before slot: (1)
value in slot: (1, 2)
value after slot: (1)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Как сделать чтоб в выводе я получил "value after slot: (1, 2)" ?