PDA

View Full Version : 'class QCoreApplication' has no member named 'setStyleSheet'



twewm
8th March 2014, 19:12
I simply want to use a style sheet.
I get this error when I want to Compile


C:\Erfan\C++\Exersize\QT\untitled01\main.cpp:19: error: 'class QCoreApplication' has no member named 'setStyleSheet'
QApplication::instance()->setStyleSheet(ts.readAll());
^
Here's my Code

#include "mainwindow.h"
#include <QApplication>
#include <QFile>
#include <Qtextstream>


int main(int argc, char *argv[])
{

QFile f(":qdarkstyle/style.qss");
if (!f.exists())
{
printf("Unable to set stylesheet, file not found\n");
}
else
{
f.open(QFile::ReadOnly | QFile::Text);
QTextStream ts(&f);
QApplication::instance()->setStyleSheet(ts.readAll());
}

QApplication a(argc, argv);
MainWindow w;

w.show();

return a.exec();
}

Radek
8th March 2014, 20:03
Try shifting QApplication a(argc, argv) a bit up and use rather a.setStyleSheet() than QApplication::instance().

(1) When you call QApplication::instance() there is no QApplication instance around.
(2) QApplication::instance() is an inherited method that returns QCoreApplication * Even if the program compiled, the returned pointer would be NULL.
(3) If you want QApplication::instance() anyway use dynamic_cast.