Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. How to create object -dialog- from library ?
Forum Updated to NodeBB v4.3 + New Features

How to create object -dialog- from library ?

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
15 Posts 3 Posters 791 Views 3 Watching
  • 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.
  • SGaistS SGaist

    Hi,

    .dll files are shared libraries.

    @AnneRanch said in How to create object -dialog- from library ?:

    and Linux is fond of "static" library.

    That's wrong. Take a look at your Linux applications, they are all using shared libraries.

    As for your original question, you should use it in the same manner as any other libraries. There's really not much more to it than that.

    Add the path to you library headers to the INCLUDEPATH of the projects where you want to use it and add the path and library name to the LIBS variable.

    A Offline
    A Offline
    Anonymous_Banned275
    wrote on last edited by
    #5

    I am sorry, but I missed your last reply.

    So this is duplicate post AND still need a solution.
    Where is the header file?
    Was it added by wizards ??

    If the library header DOES not exists compiler usually complains .
    My code builds - no problem.

    Still missing "header" reference in main project.

    After following almost 30 steps in coding main project and adding test library
    I am sill missing "header" reference in main project.

    Normally - main project should have included library header file..

    Default rules for deployment.

    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target

    unix:!macx: LIBS += -L$$PWD/../build-TestLibraryProject-Desktop_Qt_5_15_2_GCC_64bit-Debug/ -lTestLibraryProject

    INCLUDEPATH += $$PWD/../build-TestLibraryProject-Desktop_Qt_5_15_2_GCC_64bit-Debug
    DEPENDPATH += $$PWD/../build-TestLibraryProject-Desktop_Qt_5_15_2_GCC_64bit-Debug

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #6

      INCLUDEPATH should point to the folder(s) where you library headers reside.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply
      0
      • SGaistS SGaist

        INCLUDEPATH should point to the folder(s) where you library headers reside.

        A Offline
        A Offline
        Anonymous_Banned275
        wrote on last edited by
        #7

        @SGaist I think I found the "problem```
        The library is L/l "linked" correctly, but in separate folder, not in same as the project. I do nor recall specifying such folder ...

        However the INCLUDEPATH is just that - include PATH only .

        Looks as the library HEADER has to be added manually
        WHERE and HOW?

        Did I missed part of the wizard ?
        I did this years ago I do not recall how I solved it - my old project is long gone.
        I keep better log now

        unix:!macx: LIBS += -L$$PWD/../build-TestLibraryProject-Desktop_Qt_5_15_2_GCC_64bit-Debug/ -lTestLibraryProject

        INCLUDEPATH += $$PWD/../TestLibraryProject
        DEPENDPATH += $$PWD/../TestLibraryProject

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #8

          No, there should be no need to add any header. Your custom library should be used like any other library that resides in a non system path.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Anonymous_Banned275
            wrote on last edited by
            #9

            Help me to understand or disagree

            1. I am adding external library
              I am selecting :

            2. Library type - as selected - hence Linux

            3. (Actual ) Library file ...so - links fine

            4. (Actual ) Library path - as above

            5. Nowhere in this step / dialog there is a reference to "include " header or no actual PATH to the library source / header

            6. There is not or I just cannot see it , a reference tying main and library projects .pro files together.

            453941da-0266-43f9-9aff-fd9aaa5eb671-image.png

            1 Reply Last reply
            0
            • A Offline
              A Offline
              Anonymous_Banned275
              wrote on last edited by
              #10

              OK, I am not sure this is correct approach, but so far it works - main app builds
              test dialogs from two "shared" libraries.

              1. Create real "sub project"
              2. Add main app project to it as new main sub project
              3. Create / add Linux library as add new sub project
              4. Add newly created library to main app (sub project) - as an internal (!) library - using defaults.
              5. ADD library include headers to main sub project (!)
              6. rebuild "sub project" , run and watch for smoke...

              9e50edf7-9390-404a-9b3a-d20a9acff02f-image.png

              #include "mainwindow.h"
              #include "ui_mainwindow.h"
              
              
              // add library includes
              #include "SUB_LIBRARY_1_global.h"
              #include "testdialog.h"
              #include "sub_library_1.h"
              
              #include "SUB_LIBRARY_2_global.h"
              #include "testdialog_1.h"
              #include "sub_library_2.h"
              
              MainWindow::MainWindow(QWidget *parent)
                  : QMainWindow(parent)
                  , ui(new Ui::MainWindow)
              {
                  ui->setupUi(this);
                 TESTDialog *TD = new  TESTDialog();
                 TD->show();
              
                 TESTDialog_1 *TD_1 = new  TESTDialog_1();
                 TD_1->show();
              }
              
              MainWindow::~MainWindow()
              {
                  delete ui;
              }
              
              
              

              21834534-d262-4cd9-a964-50464e964e58-image.png

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #11

                You should only include the header of the class you use. There should be no need to include the XXX_global.h which I guess contains the export macros and are is already included in the header of the classes you wrote in your libraries.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                A 1 Reply Last reply
                1
                • SGaistS SGaist

                  You should only include the header of the class you use. There should be no need to include the XXX_global.h which I guess contains the export macros and are is already included in the header of the classes you wrote in your libraries.

                  A Offline
                  A Offline
                  Anonymous_Banned275
                  wrote on last edited by
                  #12

                  @SGaist I have cheated a little . When I did this exercise with my previous project I did checked include guards ., Not this time , but I do not have multiple includes anyway... Just being lazy or let the code do its work...

                  However, I am not totally out of the woods...,

                  Using "sub-project" to manage main and library so far only works when I add " new sub project- library. " and then add newly created library to main project.
                  (I realize these terms sound stupid but I am no going to invent my own terminology - this is a TWO step process

                  1. create and add library as sub project
                  2. add / link such library to main project

                  So far I am back to very original question - doing the above with EXISTING project / library does not function.

                  The existing code is NOT in sub project tree...

                  ![00fd527f-8768-4501-b8a0-e2a224eb7918-image.png](https://ddgobkiprc33d.cloudfront.net/4ed24e94-332d-4bab-be01-90d52fe6c3f2.png) code_text
                  

                  Here is btscanner in my SUB_PROJECT_1

                  6c3b2613-bef4-475e-a793-0e7d1bea7e9e-image.png

                  Here is my device.ui form in QTDesigner

                  346890f4-47ff-49ef-965d-8b525ab06f0a-image.png

                  ..and here is my ":run time" dialog

                  obviously NOT the same form as in SUB_PROJECT_1
                  9c30a9f6-e333-4b9f-a9d7-dcfa6974a0c0-image.png

                  PS I do not expect much help from the group
                  on this one. Hope it is "back" to inlcudes...

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mchinand
                    wrote on last edited by
                    #13

                    The 'Include path' line in the dialog should be set to the folder where the header files (*.h) of the library are located and not the build folder.

                    In regards to it not asking for the location of a .pro file, this is for adding any external library, so it does not have to be a Qt-based library built using a .pro file. Also, an external library in this case refers to a pre-built library (the .so/.a/.dll/.lib file already exists) and won't be compiled as part of your project so there is no need for your project to know about the library's .pro file.

                    1 Reply Last reply
                    1
                    • A Offline
                      A Offline
                      Anonymous_Banned275
                      wrote on last edited by
                      #14

                      Appreciate the comments however it does no explaining the relations between subproj and its projects. I still would like for somebody to confirm or dispute the way I am coding my project. I am avoiding terms build or create here.

                      I start with coding TEST_SUBDIR_PROJECT
                      New File ->Other project -subdir.
                      the result is ability to add (first) executable subproject.
                      I usually start with add of QT application - widget.
                      After that I "build " and "run" the application.
                      There are no includes / external libraries / internal libraries - all standard QT application .

                      Then I add new TEST C++ library as a independent project

                      Then I add TEST C++ library as new subproject to TEST_SUBDIR_PROJECT

                      That is another sub project managed by subdirs. BUT it is now an internal library too. Not useful at this point.

                      BUT it can be added as library to both TEST_SUBDIR_PROJECT ,pro and MAIN .pro files.
                      I have not figured out how TEST_SUBDIR_PROJECT .pro can use it , but it allows MAIN .pro file to use the added TEST library - and that is the entire purpose of this excise....

                      NOW I can add required includes to main.cpp and ACTUALLY USE the library.

                      THE (hopefully) LAST and repeated question remains - what are all these includes in
                      TEST C++ library FOR?

                      QT -= gui widgets dialog
                      QT += widgets
                      #added widgts
                      TEMPLATE = lib
                      DEFINES += TEST_LIBRARY_LIBRARY
                      
                      CONFIG += c++11
                      
                      # You can make your code fail to compile if it uses deprecated APIs.
                      # In order to do so, uncomment the following line.
                      #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
                      
                      SOURCES += \
                          test_library.cpp \
                          testdialog.cpp
                      
                      HEADERS += \
                          TEST_LIBRARY_global.h \
                          test_library.h \
                          testdialog.h
                      
                      # Default rules for deployment.
                      unix {
                          target.path = /usr/lib
                      }
                      !isEmpty(target.path): INSTALLS += target
                      
                      FORMS += \
                          testdialog.ui
                      
                      

                      Next step is to convert existing .pro (QT excising example brscanner) to library , add it as library subproject and then add it as another library (now internal) to the main project.

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        Anonymous_Banned275
                        wrote on last edited by
                        #15

                        Could somebody kindly help me to figure out LAST part of my LAST post ?

                        Since I am a lazy person I like to reuse somebody else code.

                        I have made wrong choice and reused "btscanner" example BUT I modified it and interwoven it into my code. Now I regret this.
                        I am now using the same code as a library and have modified my main code as such. It works with ONE exception - I need to remove all of the interwoven code .
                        Part of the removal is to REMOVE references added to my .pro files - including "includes ". ( see mine previous post )

                        I prefer NOT to remove these references without some knowledge what is their purpose.
                        Personally since I am now able to modify the library code I would prefer other ways to discard the interwoven code - perhaps renaming the files...

                        1 Reply Last reply
                        0

                        • Login

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