PDA

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



furskytl
16th September 2011, 14:28
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!

Lykurg
16th September 2011, 14:58
Nothing wrong so far. Probably you have to rebuild, but could you please post the full error during the building progress.

wysota
16th September 2011, 15:20
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).

furskytl
17th September 2011, 14:04
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!!!