Menu

Extending Qt class

2015-05-05
2015-05-22
  • Cabieces Julien

    Cabieces Julien - 2015-05-05

    Hi,

    I'm using CppCheck (version 1.69) on linux to check code quality for a project depending on Qt.

    My problem is that when my class extends Qt class (QMainWindow, QWidget, QDialog, ...), CppCheck fail to report some rules, like "functionConst" for instance.

    Example:

    #include <QMainWindow>
    
    class A : public QMainWindow
    {
    public:
        int f()
        {
            return _a;
        }
    
        int _a;
    }
    

    I try to use the option "--library=qt.cfg" but it works only for macros definitions. I try to include Qt headers (with --force because of many config), but it still not works. Maybe it's due to missing system include, but cppcheck try to find includes from all Qt supported OS (winbase.h for instance).

    Did you have any idea on how I could deal with Qt includes.

    Thanks for your great job,

    Have a nice day,
    Julien

     
  • Daniel Marjamäki

    when QMainWindow is unknown it is assumed that f is virtual.

    You get a warning for this code:

    class QMainWindow {};
    
    class A : public QMainWindow
    {
    public:
        int f()
        {
            return _a;
        }
    
        int _a;
    };
    

    I am not sure how this is configured properly. I feel skeptic about including the qt headers.. and you also said it doesn't help. but that is what you should do and we may need to fix some problem with that.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.