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 use part of one project in other project?
Forum Updated to NodeBB v4.3 + New Features

How to use part of one project in other project?

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
6 Posts 2 Posters 3.8k Views 1 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.
  • D Offline
    D Offline
    Draqun
    wrote on last edited by
    #1

    Hi.

    This is my first real app with QT and QtCreator. Can someone tell me how in QtCreator 3.5.1 in Ubuntu use part of one project into another? Directory three looks that

    Project/
        my-qt-project/
            inc/
               #some headers
            src/
                #some sources
            main.cpp
        my-qt-project-gui/
            main.cpp
            #other sources
    

    my-qt-project is a console version of app. The second one is version with GUI which use a lot of code from the first one, but I cannot import headers and compile it. In project build settings I set my-qt-project as a dependency.

    There a simple way to share part of one project with another? I tried use https://wiki.qt.io/SUBDIRS_-_handling_dependencies but it does not work.
    http://stackoverflow.com/questions/16876690/qt-creator-how-do-i-add-one-c-project-to-another - I was here too.

    Best regards.
    Draqun

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

      Hi and welcome to devnet,

      The subdirs template is the right thing to use. Usually you would create one or more library projects with the common code and then one project per application.

      What did you try exactly ? Can you share your .pro files ?

      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
      • D Offline
        D Offline
        Draqun
        wrote on last edited by
        #3

        Basic project

        CONFIG += c++11
        QMAKE_CXXFLAGS += -std=c++11
        QT += sql
        QT -= gui
        TEMPLATE = app
        TARGET = qt-simple-notifier
        INCLUDEPATH += . \
                        include
        
        # Input
        SOURCES += main.cpp \
            src/QtSimpleNotifier/DatabaseManager.cpp
        
        DISTFILES += \
            LICENSE \
            README.md
        
        HEADERS += \
            inc/QtSimpleNotifier/DatabaseManager.h
        

        Project with GUI

        template = subdirs
        SUBDIRS += ../qt-simple-notifier
        
        #include(../qt-simple-notifier/qt-simple-notifier/inc/*)
        #include(../qt-simple-notifier/qt-simple-notifier/src/*)
        
        INCLUDEPATH += ../qt-simple-notifier
        CONFIG += c++11
        QMAKE_CXXFLAGS += -std=c++11
        QT       += core gui
        
        greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
        
        TARGET = qt-simple-notifier-gui
        TEMPLATE = app
        
        
        SOURCES += main.cpp \
                mainwindow.cpp \
            addreminderdialog.cpp
        
        HEADERS += mainwindow.h \
            addreminderdialog.h
        
        FORMS    += mainwindow.ui \
            addreminderdialog.ui
        
        RESOURCES += \
            resources.qrc
        
        DISTFILES += \
            LICENSE \
            README.md
        

        My *.pro files.

        I don;t want create library project with shared code. I just want include and compile a few class in project with GUI from project with console interface.

        Best regards.

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

          Even without a library, your design is wrong.

          You should have something like:

          -- MyProject
          ---- cli_project
          ---- gui_project

          With MyProject being the subdirs template pointing to the other two. Then in your GUI project you'll use SOURCES += ../cli_project/file_you_want.cpp etc.

          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
          1
          • D Offline
            D Offline
            Draqun
            wrote on last edited by Draqun
            #5

            That was more complicated than I thought.
            Thanks for help. Now all work fine.

            https://github.com/Draqun/qt-reminder - link to project with valid files.

            Best regards.

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

              Why are you adding the src folder to INCLUDEPATH?

              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

              • Login

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