Results 1 to 4 of 4

Thread: How to use private static variable in a class? error: collect2: ld returned 1 exit

  1. #1
    Join Date
    Sep 2011
    Posts
    24
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Question How to use private static variable in a class? error: collect2: ld returned 1 exit

    I am an stranger to Qt.I use a private static variable in a class,like this:
    private:
    static QString lastFilePath ;
    However it doesn't work with the complie output "collect2: ld returned 1 exit status"!If I delete the keyword "static",it can run normally!What's wrong with my code?How to define a static member in a class in Qt?Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to use private static variable in a class? error: collect2: ld returned 1 exi

    Nothing wrong so far. Probably you have to rebuild, but could you please post the full error during the building progress.

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

    Default Re: How to use private static variable in a class? error: collect2: ld returned 1 exi

    It's not a matter of Qt. It's a matter of using static variables in C++. I suggest you google for explanations how to use static variables in C++ (hint: you have to initialize the variable).
    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
    Sep 2011
    Posts
    24
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to use private static variable in a class? error: collect2: ld returned 1 exi

    Yes,thanks very much!The reason is that I really have to initialize or redeclare the variable in the class definition *.cpp file like this :
    QString NewRingDialog::lastFilePath = "";
    !
    I have learned C++ for 2 years but now I realize that I have forgotten some usages in c++!!! I think I need to review it!
    Thanks very much!!!
    Last edited by furskytl; 17th September 2011 at 13:08.

Similar Threads

  1. error: collect2: ld returned 1 exit status
    By Splatify in forum Newbie
    Replies: 2
    Last Post: 13th February 2011, 18:09
  2. Replies: 3
    Last Post: 23rd January 2011, 12:15
  3. error: collect2: ld returned 1 exit status
    By srohit24 in forum Qt Programming
    Replies: 3
    Last Post: 1st December 2009, 06:32
  4. error: collect2: ld returned 1 exit status
    By nataly in forum Qt Programming
    Replies: 4
    Last Post: 13th October 2009, 13:39
  5. collect2: ld returned 1 exit status error
    By gmsk19 in forum Qt Tools
    Replies: 11
    Last Post: 25th July 2009, 02:05

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.