Results 1 to 5 of 5

Thread: Copy a QMap

  1. #1
    Join Date
    Feb 2013
    Posts
    50
    Thanks
    5

    Default Copy a QMap

    Hello, I am having problems copying one QMap to another, any help would be appreciated.

    This is my code (where the copying should occur):

    PS. I have solved the issue, seems I just had to add i++ to the code below; Just one question, it seems
    the data is added in the reverse order to the Qmap. For example, when I added "param1","test1"
    key value pair to the QMap as in the end of this post, and also "param2", "test2" ... they are read in an reverse
    order in the loop below. Is it supposed to be like this?? I want the data to be added in the
    same order as I added in the code in the end.. Thanks.

    Qt Code:
    1. bool MyNetworkClass::initializeRequestParam(QMap<QString, QString> params)
    2. {
    3. QMap<QString, QString>::const_iterator i = params.constBegin();
    4. while (i != params.constEnd()) {
    5. requestParameters.insert(i.key(), i.value());
    6. i++; // added
    7. }
    8.  
    9. return true; // this is default...
    10. }
    To copy to clipboard, switch view to plain text mode 

    where
    Qt Code:
    1. requestParameters
    To copy to clipboard, switch view to plain text mode 
    is member variable:
    Qt Code:
    1. QMap<QString, QString> requestParameters;
    To copy to clipboard, switch view to plain text mode 

    Now, when I try to issue the above function:

    Qt Code:
    1. MyNetworkClass *p = new MyNetworkClass();
    2.  
    3.  
    4. QMap<QString, QString> params;
    5.  
    6. params.insert("param1", "test1");
    7. params.insert("param2", "test2");
    8. params.insert("param3", "test3");
    9.  
    10. p->initializeRequestParam(params);
    To copy to clipboard, switch view to plain text mode 

    The last line "initializeRequestParam" - seems to not work.. I think it gets in an endless loop...
    when I debugged into it, I think it managed to successfully copy only one "param1", "test1" pair to the
    Qt Code:
    1. reqestParameters
    To copy to clipboard, switch view to plain text mode 
    destination...
    Any help greatly appreciated as to how to make this function initializeRequestParam work?? and copy one QMap into another..???
    Last edited by ggdev001; 12th February 2013 at 12:18.

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

    Default Re: Copy a QMap

    You are not incrementing the iterator in your function anywhere.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Copy a QMap

    Also QMap has a copy constructor, see here.

  4. #4
    Join Date
    Feb 2013
    Posts
    50
    Thanks
    5

    Default Re: Copy a QMap

    Yes, I noticed it thanks. Could you please look at my modified question?? i.e., the P.S. part?? Thank you.

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

    Default Re: Copy a QMap

    QMap is sorted by key order.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 1
    Last Post: 27th December 2012, 06:01
  2. QSettings: copy from ini to xml? Copy group?
    By TorAn in forum Qt Programming
    Replies: 1
    Last Post: 11th January 2012, 14:51
  3. QMap
    By sophister in forum Qt Programming
    Replies: 5
    Last Post: 25th May 2009, 10:05
  4. Qmap
    By phillip_Qt in forum Qt Programming
    Replies: 3
    Last Post: 23rd November 2007, 10:43
  5. Reg - QMap(Qt3.3.4)
    By suresh in forum Newbie
    Replies: 3
    Last Post: 18th October 2006, 22:04

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
  •  
Qt is a trademark of The Qt Company.