Today I encountered a liking problem with static variable/function. First let me show you the code:
Trace.h
class Trace : public QObject
{
Q_OBJECT
public:
explicit Trace(QObject *parent = 0);
static void setLogFilePath(QString path)
{
logFilePath = path;
}
QString getLogFilePath();
private:
static QString logFilePath;
};
#endif // TRACE_H
Trace.cpp
// includes.. constructors..
QString Trace::getLogFilePath()
{
return logFilePath;
}
On Linux, I can compile this class to generate a dynamic library without any problem. On windows, I can't, I have an undefined reference to logFilePath.
I know that with TEMPLATE = app I have to define my static variables in the main, but with a library I don't think so but I'm not sure.
I saw that on windows, if put the implementation in the header file like this:
Trace.h
QString Trace::getLogFilePath()
{
return logFilePath;
}
There is no liking error.
1) Why is there a difference like this between Linux and Windows ? (Same Qt version).
2) Is using static variable in dynamic library a good thing or not ? (I can overcome this problem with a file, maybe it's better).
Thanks in advance.