samedi 26 janvier 2019

Qt5: main.obj:-1: error: LNK2001: unresolved external symbol "public: static class QPalette ColorUtils::white" (?white@ColorUtils@@2VQPalette@@A)

I define a static QPalette in colorutils.h,and init it in colorutils.cpp.
When I call it from main or something else,I got this error.
I try to clean it,run qmake and rebuilt it but it didn't work.

colorutils.h

#ifndef COLORUTILS_H
#define COLORUTILS_H

#include <QPalette>

class ColorUtils
{

public:
    ColorUtils();
    static QPalette white;
};

#endif //COlORUTILS_H

colorutils.cpp

#include "colorutils.h"

ColorUtils::ColorUtils()
{
    white.setColor(QPalette::Background, QColor(255,255,255));
}

main.cpp

#include "mainwindow.h"
#include "version.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.setPalette(ColorUtils::white); // This line is the cause of the error
    w.setFixedSize(w.width(),w.height());
    w.show();

    return a.exec();
}

Errors

main.obj:-1: error: LNK2001: unresolved external symbol "public: static class QPalette ColorUtils::white" (?white@ColorUtils@@2VQPalette@@A)
colorutils.obj:-1: error: LNK2001: unresolved external symbol "public: static class QPalette ColorUtils::white" (?white@ColorUtils@@2VQPalette@@A)

Thanks!

Aucun commentaire:

Enregistrer un commentaire