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. Undefined reference to `QCheckBox::staticMetaObject'
QtWS25 Last Chance

Undefined reference to `QCheckBox::staticMetaObject'

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.9k 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.
  • F Offline
    F Offline
    furest
    wrote on last edited by
    #1

    Hi!

    I'm trying to access my QCheckBox from C++ (it's declared in my QML app) but always en up with this error because of this code :

    QCheckBox *obj = parent()->findChild<QCheckBox*>("cbThick");
    obj->setProperty("checked", (state!=0));
    

    The object trying to call it from has been declared inside QML too (it has a QObject tag).
    This is the way I declared the type in QML :

    int main(int argc, char *argv[])
    {
        qmlRegisterType<ConnectionHandler>("MyHandler", 1, 0, "ConnectionHandler");
        QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
        QGuiApplication app(argc, argv);
        QQmlApplicationEngine engine;
        engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
        if (engine.rootObjects().isEmpty())
            return -1;
    
        return app.exec();
    }
    

    And inside QML :

    ConnectionHandler{
            id: ch
            ip: tfIP.text
            port: tfPort.text
        }
    

    I've seen the code I'm trying to compile on multiple places on forums but It seems the way I use it is different though...

    Any idea?

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @furest said in Undefined reference to `QCheckBox::staticMetaObject':

      QGuiApplication

      QCheckBox is a QWidget so you will likely need to link against QtWidgets and use a QApplication.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      3
      • F Offline
        F Offline
        furest
        wrote on last edited by
        #3

        Hi!
        Thank you a lot! I compiles (I think it must work then...)
        A bit of google research helped me (in case any newbie like me has trouble finding out):

        Link against widgets : edit your project.pro and add widget to that line, like this:

        QT += quick widgets
        

        Then just include QApplication in your main.cpp:

        #include <QApplication>
        

        And change your QGuiApplication app to a QApplication app

        1 Reply Last reply
        1

        • Login

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