Results 1 to 2 of 2

Thread: 'class QCoreApplication' has no member named 'setStyleSheet'

  1. #1
    Join Date
    Mar 2014
    Posts
    1
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default 'class QCoreApplication' has no member named 'setStyleSheet'

    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
    Qt Code:
    1. #include "mainwindow.h"
    2. #include <QApplication>
    3. #include <QFile>
    4. #include <Qtextstream>
    5.  
    6.  
    7. int main(int argc, char *argv[])
    8. {
    9.  
    10. QFile f(":qdarkstyle/style.qss");
    11. if (!f.exists())
    12. {
    13. printf("Unable to set stylesheet, file not found\n");
    14. }
    15. else
    16. {
    17. f.open(QFile::ReadOnly | QFile::Text);
    18. QTextStream ts(&f);
    19. QApplication::instance()->setStyleSheet(ts.readAll());
    20. }
    21.  
    22. QApplication a(argc, argv);
    23. MainWindow w;
    24.  
    25. w.show();
    26.  
    27. return a.exec();
    28. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    258
    Thanks
    3
    Thanked 65 Times in 59 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: 'class QCoreApplication' has no member named 'setStyleSheet'

    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.

  3. The following user says thank you to Radek for this useful post:

    twewm (8th March 2014)

Similar Threads

  1. Class 'QWidge't has no member named 'setSize'
    By Omicron in forum Qt Programming
    Replies: 5
    Last Post: 3rd April 2011, 16:48
  2. accessing static member variables of one class in another class
    By jasonknight in forum General Programming
    Replies: 5
    Last Post: 6th September 2010, 14:53
  3. Replies: 4
    Last Post: 29th May 2010, 12:56
  4. Replies: 2
    Last Post: 29th June 2009, 06:09
  5. Replies: 5
    Last Post: 14th July 2006, 22:42

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.