PDA

View Full Version : GCC problem with QHash as optionnal parameter in function



nooky59
17th July 2008, 10:32
Hello,

I usually compile my code with the MSVC compiler but I tried yesterday to compile it on Mac OS X with GCC.

I have a function declared like that :



void myfunction(const QHash<QString, QVariant> &callback = QHash<QString, QVariant>());


It compiles well in MSVC but it seems GCC as some troubles with such a construct.

I have changed my code to take a pointer :



void myfunction(const QHash<QString, QVariant> *callback = 0);


But is there a way to keep a construct without pointer which accept such an optionnal parameter with a template class ?

wysota
17th July 2008, 12:05
Try typedeffing the hash.

somekool
11th March 2012, 23:51
I am having the same problem, compiling akonadi 1.7.1 with Qt 4.8.0 under Snow Leopard.
I know this thread is 4 years old, that's make me even more surprise.

thank you for the suggestion, typedeffing it worked.

but couldn't this be fixed?

it feels weird to me to fill a "bug" report to akonadi about it ... but anyway..

thanks

ChrisW67
12th March 2012, 01:45
What version of GCC and what is the error message?

My GCC 4.5.3, Qt 4.7.4 on Linux produces no error or warning on this:


#include <QtCore>
#include <QDebug>

void myfunction(const QHash<QString, QVariant> &callback = QHash<QString, QVariant>())
{
qDebug() << callback.keys();
}

int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);

myfunction();

QHash<QString, QVariant> h;
h.insert("A", QVariant(1));
h.insert("B", QVariant(1));
myfunction(h);

return 0;
}