I’m using VisualStudio 2010 to build a simple program with Qt 4.8.3, and i’m having trouble with a simple method definition:
here is my code:
GuiHelper.h
#ifndef GUIHELPER_H
#define GUIHELPER_H
#include "GuiHelper.cpp"
#include <QString>
#include <QWidget>
#include <QFile>
class GuiHelper
{
private:
static void useStyleSheet(QString, QWidget*);
};
#endif //GUIHELPER_H
and GuiHelper.cpp:
#include <QString>
#include <QWidget>
#include <QFile>
#include "GuiHelper.h"
void GuiHelper::useStyleSheet(QString filename, QWidget* widget)
{
// loads style file and apply style
QFile file(":/Resources/"+filename);
file.open(QFile::ReadOnly);
QString styleSheet = QLatin1String(file.readAll());
widget->setStyleSheet(styleSheet);
}
I get the error C2653: GuiHelper is not a class or a namspace but I don’t really see what’s wrong…
I also checked “no precompiled headers” when creating the project with the QT addin
thanks!
Quickfix – remove the
from the header.
Cause of the problem: the compiler compiles the sources – that is the
.cppfiles. It starts parsing the cpp file and reacheswhich tells it to process the header and paste its contents – the second line of the header does
Afterwards, you
which in turn attempts to process and paste the
cppfile, which again tries to process the header. BecauseGUIHELPER_Hwas already defined, the header is no longer processed, but remember that the class was not yet defined. So it gets to the linebut you get the error because
GuiHelperwas not defined yet.