Results 1 to 4 of 4

Thread: initialize static qstringlist and qlist<qstring>

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2013
    Posts
    45
    Thanks
    23
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default initialize static qstringlist and qlist<qstring>

    hi

    how can i do initialize static qstringlist and qlist<qstring> ?

    I get this message without initialize staic QStringList :

    mainwindow.obj:-1: error: LNK2001: unresolved external symbol "private: static class QStringList MainWindow::list" (?list@MainWindow@@0VQStringList@@A)
    I get the same error message for the static qlist<qstring> !

  2. #2
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: initialize static qstringlist and qlist<qstring>

    Qt Code:
    1. //in CYourClass.h file
    2. CYourClass
    3. {
    4. private:
    5. static QList<QString> m_strList;
    6. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. //in CYourClass.cpp file
    2. #include "cyourclass.h"
    3.  
    4. QList<QString> CYourClass::m_strList;
    5.  
    6. CYourClass::CYourClass()
    7. {
    8.  
    9. }
    To copy to clipboard, switch view to plain text mode 

    Follow the same for QStringList also.

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

    Default Re: initialize static qstringlist and qlist<qstring>

    Quote Originally Posted by smemamian View Post
    how can i do initialize static qstringlist and qlist<qstring> ?
    Exactly the same way you initialize a static int or a static bool.
    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.


  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: initialize static qstringlist and qlist<qstring>

    Small addition to rawfool's post

    Qt Code:
    1. //in CYourClass.h file
    2. CYourClass
    3. {
    4. private:
    5. static QList<QString> m_strList;
    6. };
    7.  
    8. //in CYourClass.cpp file
    9. #include "cyourclass.h"
    10.  
    11. QList<QString> CYourClass::m_strList = QList<QString>() << QString("First") << QString("Second"); //<<<<<<<<<<<<<<<<<<
    12.  
    13. CYourClass::CYourClass()
    14. {
    15.  
    16. }
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  5. The following user says thank you to Santosh Reddy for this useful post:

    Mesozoic (3rd November 2015)

Similar Threads

  1. using QStringList as QList<QListWidgetItem*>
    By geleven in forum Qt Programming
    Replies: 3
    Last Post: 8th April 2010, 18:13
  2. QStringList or QList , which is faster
    By BalaQT in forum Newbie
    Replies: 3
    Last Post: 3rd April 2010, 08:48
  3. initialize QStringList with integers
    By tommy in forum Newbie
    Replies: 3
    Last Post: 13th May 2009, 06:48
  4. Replies: 2
    Last Post: 19th September 2008, 05:21
  5. Initialize QDateTime by a QString
    By mattia in forum Newbie
    Replies: 2
    Last Post: 14th March 2008, 13:42

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.