QVariant will accept a void*, so if you are willing to discard type safety:
int *my_array = new int[5];
int *p1 = static_cast<int*>( v1.value<void*>() );
delete[] my_array;
int *my_array = new int[5];
QVariant v1 = QVariant::fromValue( static_cast<void *>(my_array) );
int *p1 = static_cast<int*>( v1.value<void*>() );
delete[] my_array;
To copy to clipboard, switch view to plain text mode
or, you can declare int* to the meta-type system:
Q_DECLARE_METATYPE(int*)
// and then
int *p2 = v2.value<int*>();
Q_DECLARE_METATYPE(int*)
// and then
QVariant v2 = QVariant::fromValue(my_array);
int *p2 = v2.value<int*>();
To copy to clipboard, switch view to plain text mode
Before you run off passing the pointer... you are passing a pointer to a block of memory (that might not exist) without passing the size of the block. How is the receiver supposed to know how many elements (ints in this case) can be safely accessed through that pointer?
Have you considered using QVector<int>?
Q_DECLARE_METATYPE(QVector<int>)
QVector<int> my_array(5);
QVector<int> a = v3.value<QVector<int> >();
qDebug() << a.size();
Q_DECLARE_METATYPE(QVector<int>)
QVector<int> my_array(5);
QVariant v3 = QVariant::fromValue(a);
QVector<int> a = v3.value<QVector<int> >();
qDebug() << a.size();
To copy to clipboard, switch view to plain text mode
This will copy the data if you modify the data at the receiving end but for read-only purposes is quite efficient.
Bookmarks