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. [SOLVED] qmake. including *.pri file due to condition

[SOLVED] qmake. including *.pri file due to condition

Scheduled Pinned Locked Moved Qt Creator and other tools
7 Posts 2 Posters 7.2k 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.
  • _ Offline
    _ Offline
    _Dima
    wrote on last edited by
    #1

    I'm trying to include source and header files by using "include *.pri" and due to some condition (also in the pri file)

    There are few following project's files:
    configure.pri
    @
    brand_number = 2

    isEqual(brand_number, "1"){
    project_name = project1
    }

    isEqual(brand_number, "2"){
    project_name = project2
    }

    message(project_name = $$project_name)
    @

    test_include_1/test_1.pri
    @
    SOURCES += test_include_1/test.cpp
    HEADERS += test_include_1/test.h
    INCLUDEPATH += test_include_1
    @

    test_include_2/test_2.pri
    @
    SOURCES += test_include_2/test.cpp
    HEADERS += test_include_2/test.h
    INCLUDEPATH += test_include_2
    @

    project1.pro
    @
    include(configure.pri)

    QT += core widgets
    TEMPLATE = app
    TARGET = $$project_name

    SOURCES += main.cpp
    mainwindow.cpp
    HEADERS += mainwindow.h
    FORMS += mainwindow.ui

    isEqual(brand_number,"1"){
    include(test_include_1/test_1.pri)
    message("include test_1.pri")
    }else:isEqual(brand_number,"2"){
    include(test_include_2/test_2.pri)
    message("include test_2.pri")
    }
    else{
    error("The parameter brand_number is incorrect!")
    }
    @

    Why "test_include_1/test_1.pri" is also included?!
    I see it in the project file's tree and "test_include_1/test_1.cpp" sometimes is included to Makefile. But sometimes is not.

    !http://oi61.tinypic.com/34grod4.jpg(File's tree in the QtCreator)!

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

      Hi,

      IIRC Qt Creator doesn't handle that the same way as qmake, it just shows what you have in your project not what the current configuration will use. Which is IMHO better, this way you don't need to fiddle your project every time you want to modify test_2 or test_1

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

        [quote author="SGaist" date="1396905761"]Hi,

        IIRC Qt Creator doesn't handle that the same way as qmake, it just shows what you have in your project not what the current configuration will use. Which is IMHO better, this way you don't need to fiddle your project every time you want to modify test_2 or test_1[/quote]

        Hi SGaist,
        I wouldn't be care if QtCreator builds only one include during building always. But sometimes QtCreator builds both includes test_1 and test_2!

        And I've forgot to notice that in the real project the name of pri file is calculated dinamically.... Foolowing project file blows QtCreator's mind...
        @
        #configuration
        new_ui = 0
        brand_number = 1

        isEqual(brand_number,"0"){
        include1=test_a
        include2=
        }else:isEqual(brand_number,"1"){
        include1=test_b
        include2=
        }else:isEqual(brand_number,"2"){
        include1=
        include2=test_c
        }else:isEqual(brand_number,"3"){
        include1=
        include2=test_c
        #unknown brand number
        }else{
        error("Unknown brand number '$$brand_number' !")
        }

        message(project_name = $$project_name)
        message(new_ui = $$new_ui)
        message(brand_number = $$brand_number)
        message(include1 = $$include1)
        message(include2 = $$include2)

        QT += core widgets
        TEMPLATE = app
        TARGET = test_project

        SOURCES += main.cpp
        mainwindow.cpp
        HEADERS += mainwindow.h
        FORMS += mainwindow.ui

        isEqual(new_ui,"1"){
        include(new_ui/new_ui.pri)
        }else:!isEmpty(include1){
        include($$include1/$$include1".pri")
        }else:!isEmpty(include2){
        include($$include2/$$include2".pri")
        }
        else{
        error("The parameter brand_number is incorrect!")
        }
        @

        !http://oi59.tinypic.com/ac8j9v.jpg(What is the...)!

        1 Reply Last reply
        0
        • _ Offline
          _ Offline
          _Dima
          wrote on last edited by
          #4

          Oh!!! I've found the solution!
          Necessary to confuse QtCreator :)
          If the QtCreator cannot to calculate name of the included pri files then it doesn't include them. So we can use name of the included pri file like a variable and (!) this variable has to have few possible values in the project file.
          For example:
          @
          brand_number = 1

          isEqual(brand_number,"1"){
          included_file_path = test_a
          }else{
          included_file_path = undefined
          error("brand_number is incorrect!")
          }

          QT += core widgets
          TEMPLATE = app
          TARGET = test_project

          SOURCES += main.cpp
          mainwindow.cpp
          HEADERS += mainwindow.h
          FORMS += mainwindow.ui

          !isEmpty(included_file_path){
          include($$included_file_path/$$included_file_path".pri")
          }
          @

          If we delete line "included_file_path = undefined" then QtCreator calculates name of the pri file (because "included_file_path " can have only one value) and "included_file_path" will be included in the file tree every time and sometimes building will be failed...

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

            This looks a bit like a corner case. You should talk about it on the qt-creator mailing list, you'll find Qt Creator's developers/maintainers there

            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
            • _ Offline
              _ Offline
              _Dima
              wrote on last edited by
              #6

              I now that it is corner case, but I have to provide with completed result and I'm compelled to resort to this way.

              Could you please advise where is it "qt-creator mailing list"? Is it some forum or just e-mail address?

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

                It's "here":http://lists.qt-project.org/mailman/listinfo/qt-creator

                Don't forget to register first

                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