Results 1 to 2 of 2

Thread: QMap Problem with arguments.

  1. #1
    Join Date
    Mar 2006
    Location
    Vadodara, Gujarat, India
    Posts
    65
    Thanks
    16
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QMap Problem with arguments.

    hi all,
    i m making a QMap just like below:
    Qt Code:
    1. QMap<QString,stack&> undoMap,redoMap;
    To copy to clipboard, switch view to plain text mode 

    and the error i get is as below:
    C:\Qt\4.1.3\include\QtCore\../../src/corelib/tools/qmap.h(159) : warning C4181: qualifier applied to reference type ignored
    ..\include\mapStack.h(8) : see reference to class template instantiation 'QMap<class QString,class stack &>' being compiled
    if i change the second parameter to pointer, it sompiles fine. can't we pass anything as parameters in QMap as well as QHash.

    When shall i use QMap and QHash ?

    Thanx in advance
    Do what u r afraid to do, and the death of fear is sure.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QMap Problem with arguments.

    You cannot store references.

    From docs:
    The values stored in the various containers can be of any assignable data type. To qualify, a type must provide a default constructor, a copy constructor, and an assignment operator. This covers most data types you are likely to want to store in a container, including basic types such as int and double, pointer types, and Qt data types such as QString, QDate, and QTime, but it doesn't cover QObject or any QObject subclass (QWidget, QDialog, QTimer, etc.). If you attempt to instantiate a QList<QWidget>, the compiler will complain that QWidget's copy constructor and assignment operators are disabled. If you want to store these kinds of objects in a container, store them as pointers, for example as QList<QWidget *>.
    Quote Originally Posted by ankurjain
    When shall i use QMap and QHash ?
    QMap:
    This provides a dictionary (associative array) that maps keys of type Key to values of type T. Normally each key is associated with a single value. QMap stores its data in Key order; if order doesn't matter QHash is a faster alternative.
    QHash:
    This has almost the same API as QMap, but provides significantly faster lookups. QHash stores its data in an arbitrary order.
    Use associative containers like map or hash when you want to associate values to some specific keys. Search google for more information on "STL containers".
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    ankurjain (24th May 2006)

Similar Threads

  1. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  2. QMap destructor bug
    By Ruud in forum Qt Programming
    Replies: 6
    Last Post: 8th April 2006, 09:08
  3. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.