Nominate our 2022 Qt Champions!

Subdirs and QUiLoader, undefined reference

  • I modified my project to subdirs format


    Now I'm having the error undefined reference to QUiLoader

    @/TecTracker/TecTrackerApp/LoadUi/loadui.cpp:9: error: undefined reference to `QUiLoader::QUiLoader(QObject*)'@

    I've added QT + = uitools the file


    Project created by QtCreator 2014-06-14T15:17:07

    QT += widgets uitools

    QT -= gui

    TARGET = LoadUi
    TEMPLATE = lib
    CONFIG += staticlib

    SOURCES += loadui.cpp

    HEADERS += loadui.hpp
    unix {
    target.path = /usr/lib
    INSTALLS += target

    Below are the other project files


    TEMPLATE = subdirs

    SUBDIRS +=



    Project created by QtCreator 2014-06-14T14:39:32


    INCLUDEPATH += ../LoadUi

    QT += testlib

    QT -= gui

    TARGET = loaduitest
    CONFIG += console
    CONFIG -= app_bundle

    TEMPLATE = app

    SOURCES += ../LoadUi/loadui.cpp
    DEFINES += SRCDIR=\"$$PWD/\"

    HEADERS +=


    #ifndef LOADUI_HPP
    #define LOADUI_HPP

    #include <QtWidgets/QWidget>
    #include <QtUiTools/QUiLoader>
    #include <QString>
    #include <QFile>

    class LoadUi
    explicit LoadUi();
    QWidget* createForm(const QString, QWidget* = 0);


    #include "loadui.hpp"


    QWidget *LoadUi::createForm(const QString url, QWidget *parent) // Return object QWidget
    QUiLoader loader;
    QFile ui_file(url);;
    QWidget* widget = loader.load(&ui_file, parent); // Load .ui file and return pointer for object created

    return widget;

  • Lifetime Qt Champion


    Since you are rebuilding your libraries sources is the tests you also need to add

    @QT += uitools@


  • Perfect!

    But because it was necessary to include in the two project files?

  • Another question.

    I already added the path in project file, for files that are in another subdir. But the Creator does not detect the file to include in this way does not trigger the code assistance.


    Despite the creator not identify the inclusion, the code compiles without errors.

  • By some miracle the creator began to detect

  • Lifetime Qt Champion

    It's necessary because you don't use the static lib you are creating but you recompile all the files from it.

Log in to reply