Subdirs and QUiLoader, undefined reference



  • I modified my project to subdirs format

    !http://i58.tinypic.com/ven80j.png(MyStructureProject)!

    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 LoadUi.pro

    @#-------------------------------------------------

    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

    @

    TecTrackerApp.pro

    TEMPLATE = subdirs

    SUBDIRS +=
    Tests
    LoadUi
    @

    @

    Tests.pro

    #-------------------------------------------------

    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 +=
    loaduitest.hpp
    ../LoadUi/loadui.hpp
    @

    codes

    @
    #ifndef LOADUI_HPP
    #define LOADUI_HPP

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

    class LoadUi
    {
    public:
    explicit LoadUi();
    ~LoadUi();
    QWidget* createForm(const QString, QWidget* = 0);
    };

    #endif
    @

    @
    #include "loadui.hpp"

    LoadUi::LoadUi()
    {
    }

    QWidget *LoadUi::createForm(const QString url, QWidget *parent) // Return object QWidget
    {
    QUiLoader loader;
    QFile ui_file(url);

    ui_file.open(QFile::ReadOnly);
    QWidget* widget = loader.load(&ui_file, parent); // Load .ui file and return pointer for object created
    ui_file.close();

    return widget;
    }
    @


  • Lifetime Qt Champion

    Hi,

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

    @QT += uitools@

    to Tests.pro



  • 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.

    !http://i57.tinypic.com/33ah06s.png(mycreator)!

    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
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.