Results 1 to 4 of 4

Thread: GCC problem with QHash as optionnal parameter in function

  1. #1
    Join Date
    Nov 2007
    Posts
    53
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default GCC problem with QHash as optionnal parameter in function

    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 :

    Qt Code:
    1. void myfunction(const QHash<QString, QVariant> &callback = QHash<QString, QVariant>());
    To copy to clipboard, switch view to plain text mode 

    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 :

    Qt Code:
    1. void myfunction(const QHash<QString, QVariant> *callback = 0);
    To copy to clipboard, switch view to plain text mode 

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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: GCC problem with QHash as optionnal parameter in function

    Try typedeffing the hash.

  3. #3
    Join Date
    Jan 2006
    Posts
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: GCC problem with QHash as optionnal parameter in function

    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

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: GCC problem with QHash as optionnal parameter in function

    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:
    Qt Code:
    1. #include <QtCore>
    2. #include <QDebug>
    3.  
    4. void myfunction(const QHash<QString, QVariant> &callback = QHash<QString, QVariant>())
    5. {
    6. qDebug() << callback.keys();
    7. }
    8.  
    9. int main(int argc, char *argv[])
    10. {
    11. QCoreApplication app(argc, argv);
    12.  
    13. myfunction();
    14.  
    15. QHash<QString, QVariant> h;
    16. h.insert("A", QVariant(1));
    17. h.insert("B", QVariant(1));
    18. myfunction(h);
    19.  
    20. return 0;
    21. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QPSQL problem
    By LoneWolf in forum Installation and Deployment
    Replies: 60
    Last Post: 4th November 2009, 14:22
  2. QPSQL driver in windows
    By brevleq in forum Installation and Deployment
    Replies: 31
    Last Post: 14th December 2007, 12:57
  3. how to add static library into qmake
    By Namrata in forum Qt Tools
    Replies: 1
    Last Post: 20th November 2007, 17:33
  4. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  5. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 12:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.