Results 1 to 5 of 5

Thread: QList<MyClass> to const QList<const MyClass>

  1. #1
    Join Date
    May 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QList<MyClass> to const QList<const MyClass>

    Hello, How can I cast a QList to a constant QList of constant values without create a new QList (create a constant view of the list)

    Example:
    Qt Code:
    1. // This not compile
    2. QList<MyClass> a;
    3. // ...
    4. const QList<const MyClass> b = a;
    To copy to clipboard, switch view to plain text mode 

    I want to use this for return the list as constant (with constant values too).

  2. #2
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: QList<MyClass> to const QList<const MyClass>

    const QList<const MyClass> b(a); could work.
    It's nice to be important but it's more important to be nice.

  3. #3
    Join Date
    May 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QList<MyClass> to const QList<const MyClass>

    I tested this solution, but does not compile.

    Thank you for reply.

  4. #4
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: QList<MyClass> to const QList<const MyClass>

    What is the error message?
    It's nice to be important but it's more important to be nice.

  5. #5
    Join Date
    May 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QList<MyClass> to const QList<const MyClass>

    The error message is:

    Qt Code:
    1. error: no matching function for call to 'QList<const MyClass>::QList(QList<MyClass>&)'
    2. note: candidates are: QList<T>::QList(const QList<T>&) [with T = const MyClass]
    3. note: QList<T>::QList() [with T = const MyClass]
    To copy to clipboard, switch view to plain text mode 

    In this moment, I am using Qt 4.6 (2010.02.1) with wingw

Similar Threads

  1. Replies: 2
    Last Post: 3rd August 2009, 16:27
  2. const member and const method
    By mickey in forum General Programming
    Replies: 8
    Last Post: 9th April 2008, 09:44
  3. Serialize myClass
    By ^NyAw^ in forum Qt Programming
    Replies: 5
    Last Post: 23rd October 2007, 10:27
  4. myclass::operator==() overload problem.
    By Nyphel in forum Qt Programming
    Replies: 4
    Last Post: 11th October 2007, 22:29
  5. Error : undefined reference to `vtable for MyClass'
    By joseph in forum Qt Programming
    Replies: 23
    Last Post: 15th June 2007, 11:21

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.