Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem when inheriting from Qwt classes

Problem when inheriting from Qwt classes

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 128 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    patrik777
    wrote on 31 Mar 2025, 21:42 last edited by
    #1

    I'm encountering a strange issue with Qwt classes. I'm getting a linker error specifically when inheriting from qwt classes(QwtPlot, QwtDial, maybe more..) like this:

    #pragma once
    #include <qwt_plot.h>
    #include <qwt_dial.h>
    #include <qwt_text.h>
    #include <QWidget>
    #include <QObject>
    #include <QLayout>
    #include <QWidget>
    
    class SimpleQwtPlot : public QwtPlot {
        Q_OBJECT
    public:
        SimpleQwtPlot(){
        QWidget* centralWidget = new QWidget();
        QVBoxLayout* layout = new QVBoxLayout(centralWidget);
        
        QwtText plotTitle("QwtPlot Test with QwtText");
        plotTitle.setFont(QFont("Arial", 12, QFont::Bold));
        plotTitle.setColor(Qt::blue);
        
        QwtPlot* plot = new QwtPlot(plotTitle, centralWidget);
        QwtPlot* plot2 = new QwtPlot(centralWidget);
        
        if (plot) {
            layout->addWidget(plot);
            
            plot->setCanvasBackground(Qt::white);
            plot->setAxisTitle(QwtPlot::xBottom, "X Axis");
            plot->setAxisTitle(QwtPlot::yLeft, "Y Axis");
        }
        
        }
    };
    

    This throws error :

    mocs_compilation_Release.obj : error LNK2019: unresolved external symbol "public: static st
    ruct QMetaObject const QwtPlot::staticMetaObject" (?staticMetaObject@QwtPlot@@2UQMetaObject
    @@B) referenced in function "public: static struct QMetaObject const * __cdecl QMetaObject:
    :staticMetaObject<&public: static struct QMetaObject const QwtPlot::staticMetaObject>(void)
    " (??$staticMetaObject@$1?staticMetaObject@QwtPlot@@2UQMetaObject@@B@QMetaObject@@SAPEBU0@X
    Z) [C:\dev\aero\testApp\build\QwtTest.vcxproj]
    C:\dev\aero\testApp\build\bin\Release\QwtTest.exe : fatal error LNK1120: 1 unresolved exter
    nals [C:\dev\aero\testApp\build\QwtTest.vcxproj]

    Ok, now you would say, that its propably linking problem, library just not getting linked. But what if i tell you, that this code compiles?:

    #pragma once
    #include <qwt_plot.h>
    #include <qwt_dial.h>
    #include <qwt_text.h>
    #include <QWidget>
    #include <QObject>
    #include <QLayout>
    #include <QWidget>
    
    class SimpleQwtPlot : public QWidget {
        Q_OBJECT
    public:
        SimpleQwtPlot(){
        QWidget* centralWidget = new QWidget();
        QVBoxLayout* layout = new QVBoxLayout(centralWidget);
        
        QwtText plotTitle("QwtPlot Test with QwtText");
        plotTitle.setFont(QFont("Arial", 12, QFont::Bold));
        plotTitle.setColor(Qt::blue);
        
        QwtPlot* plot = new QwtPlot(plotTitle, centralWidget);
        QwtPlot* plot2 = new QwtPlot(centralWidget);
        
        if (plot) {
            layout->addWidget(plot);
            
            plot->setCanvasBackground(Qt::white);
            plot->setAxisTitle(QwtPlot::xBottom, "X Axis");
            plot->setAxisTitle(QwtPlot::yLeft, "Y Axis");
        }
        
        }
    };
    

    Where is the change? I changed inheriting class from QwtPlot to QWidget. I just dont understand where is the problem. Why the hell it just dont compile with inheriting from QwtPlot, but compiles fine when it inherits from QWidget? Iam compiling in using MSVC, on linux, it worked fine. Iam using Qt 6.7.3 and Qwt 6.3.0. Iam helpless, would really appreciate any help. Thanks.

    1 Reply Last reply
    0
    • P Offline
      P Offline
      patrik777
      wrote on 31 Mar 2025, 21:57 last edited by
      #2

      Ok, so if someone enounter similiar problem:
      I resolved it removing Q_OBJECT macro.

      But could someone explain why is that? Why it didnt compile on windows using MSVC, but it did compile on linux using gcc? Why is Q_OBJECT causing the issue?

      J 1 Reply Last reply 1 Apr 2025, 05:03
      0
      • P patrik777
        31 Mar 2025, 21:57

        Ok, so if someone enounter similiar problem:
        I resolved it removing Q_OBJECT macro.

        But could someone explain why is that? Why it didnt compile on windows using MSVC, but it did compile on linux using gcc? Why is Q_OBJECT causing the issue?

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 1 Apr 2025, 05:03 last edited by
        #3

        @patrik777 I guess you did not include the generated moc file in your cpp file? See https://doc.qt.io/qt-6/moc.html

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        P 1 Reply Last reply 1 Apr 2025, 15:02
        1
        • J jsulm
          1 Apr 2025, 05:03

          @patrik777 I guess you did not include the generated moc file in your cpp file? See https://doc.qt.io/qt-6/moc.html

          P Offline
          P Offline
          patrik777
          wrote on 1 Apr 2025, 15:02 last edited by
          #4

          @jsulm But why did it work on linux, the same code tho.

          1 Reply Last reply
          0

          2/4

          31 Mar 2025, 21:57

          • Login

          • Login or register to search.
          2 out of 4
          • First post
            2/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved