I have this problem with sending array from myclass object to myclass2 function named receive(). The name of array is probesTab1 in myclass.
I try to use connect method to do this.
I have this error: undefined reference to myclass2::receive(int*)
I'm sure it's some basic knowledge, but I cant't move for few days.
"myclass.h"
#ifndef MYCLASS_H
#define MYCLASS_H
#include <QObject>
class myclass : public QObject
{
Q_OBJECT
public:
explicit myclass(QObject *parent = nullptr);
int probesTab1[3];
signals:
void pass(int * tab);
public slots:
};
#endif // MYCLASS_
myclass2.h
#ifndef MYCLASS2_H
#define MYCLASS2_H
#include <QObject>
class myclass2 : public QObject
{
Q_OBJECT
public:
myclass2();
int array[3];
public slots:
void receive(int *tab);
};
#endif // MYCLASS2_H
Main.
#include "mainwindow.h"
#include <QApplication>
#include <QDebug>
#include "myclass.h"
#include "myclass2.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
myclass Class1;
myclass2 Class2;
for(int i = 0; i<3 ; i++)
{
Class1.probesTab1[i] = i;
//I need this array to go into myclass2 function named receive()
}
int *ptr;
ptr = Class1.probesTab1;
QObject::connect(&Class1,SIGNAL(pass(int)),&Class2,SLOT(receive(int)));
emit Class1.pass(ptr);
return a.exec();
}
myclass2.cpp
#include "myclass2.h"
#include <QDebug>
myclass2::myclass2()
{
}
void receive(int values[])
{
for(int i = 0; i<3; i++)
{
qDebug() << values[i];
}
}