I use QtConcurrent::run
to run a function, and pass value by reference, but the memory address of value is different.
But if I pass value by pointer, the address is the same! I can't figure it out. Do I miss something?
Here's code.
void ptr(QString* s)
{
qDebug() << "pass by ptr: " << s;
}
void ref(QString& s)
{
qDebug() << "pass by ref: " << &s;
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString str;
QFuture<void> f1 = QtConcurrent::run(ptr, &str);
f1.waitForFinished();
QFuture<void> f2 = QtConcurrent::run(ref, str);
f2.waitForFinished();
qDebug() << "address of str: " << &str;
return a.exec();
}
Output:
pass by ptr: 0x28fefc
pass by ref: 0x525de4
address of str: 0x28fefc