Results 1 to 17 of 17

Thread: Qt initializer

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2011
    Posts
    8
    Qt products
    Qt4

    Default Qt initializer

    I need one line to initialize a QList

    This does not work,

    Qt Code:
    1. const QList<int> & test(QList<int>() << 7 << 9); //I know, I could simply write const QList<int> test(...); without using & since QList does copy only on write...but....
    To copy to clipboard, switch view to plain text mode 

    My reference points to an empty QList. Why? I thought it is equivalent to this:

    Qt Code:
    1. QList tmp;
    2. tmp << 7;
    3. tmp << 9;
    4. const QList<int> & test(tmp); //this *is* ok
    To copy to clipboard, switch view to plain text mode 


    And note that assuming there is a function fn somewhere,

    Qt Code:
    1. int fn(const QList<int> & list) {return list.size();}
    2.  
    3. fn(QList<int>() << 7 << 9); //works!! isn't it the same?
    To copy to clipboard, switch view to plain text mode 

    Thanks,
    J
    Last edited by j4l; 20th September 2011 at 11:27.

Similar Threads

  1. Replies: 1
    Last Post: 4th September 2008, 14:55
  2. expected initializer before »)« token
    By Holy in forum Qt Programming
    Replies: 2
    Last Post: 24th May 2008, 16:24

Tags for this Thread

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.