Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QMake defineReplace
Forum Updated to NodeBB v4.3 + New Features

QMake defineReplace

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 620 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.
  • S Offline
    S Offline
    Silent_Alex
    wrote on last edited by Silent_Alex
    #1

    Hi guys!
    I'm research into a qmake in current time, I have been taught how to define the self-function by some technical manual from this exmaple. However,there is a strange warning reported by Qt Creator when I had an attempt to write 'defineReplace' funtion, As following tips:
    'AddCompilerOptions' is not a recognized test function.
    the QMake code is that:

    defineReplace(AddCompilerOptions){
    
        for(compileOption,ARGS){
            QMAKE_CXXFLAGS += $$compileOption
            message("Insider option $$QMAKE_CXXFLAGS")
        }
    
        QMAKE_CXXFLAGS += $$ARGS
        return(true)
    }
    

    Additionally, it seems to not be affected for the above code, even if the key 'defineReplace' was substituted for key 'defineReplace'.
    There is nothing to be appended the variable QMAKE_CXXFLAGS When I try to print it in term of qmake function 'message' outside the scope of function AddCompilerOptions.

    thanks!

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

      Hi,

      Can you provide a minimal .pro file that can show the behaviour ?

      That said, one small difference between the example and your function is that you are not using camelCase for its name.

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

      S 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Can you provide a minimal .pro file that can show the behaviour ?

        That said, one small difference between the example and your function is that you are not using camelCase for its name.

        S Offline
        S Offline
        Silent_Alex
        wrote on last edited by
        #3

        @SGaist Hi, the minimal demo is that:

        QT       += core gui
        
        greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
        
        CONFIG += c++17
        
        QMAKE_CXXFLAGS += /std:c++17
        
        defineReplace(addCompilerOptions){
        
            for(compileOption,ARGS){
                QMAKE_CXXFLAGS += $$compileOption
                message("Insider option $$QMAKE_CXXFLAGS") #(1)
            }
        
            QMAKE_CXXFLAGS += $$ARGS
            return(true)
        }
        
        
        AddCompilerOptions(/openmp /fp:fast /diagnostics:caret)
        
        message($$quote(The option of compile $$QMAKE_CXXFLAGS)) #(2)
        
        # The following define makes your compiler emit warnings if you use
        # any Qt feature that has been marked deprecated (the exact warnings
        # depend on your compiler). Please consult the documentation of the
        # deprecated API in order to know how to port your code away from it.
        DEFINES += QT_DEPRECATED_WARNINGS
        
        include(test_a/test_a.pri)
        
        f=quote(I like your)
        k=quote(like)
        
        str_a=$$str_member($$k,0,$$num_add($$str_size($$f),-1))
        
        message("The size of Str: $$k ")
        
        # You can also make your code fail to compile if it uses deprecated APIs.
        # In order to do so, uncomment the following line.
        # You can also select to disable deprecated APIs only up to a certain version of Qt.
        #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
        
        SOURCES += \
            dialog.cpp \
            main.cpp \
            mainwindow.cpp \
            test.cpp
        
        HEADERS += \
            dialog.h \
            mainwindow.h \
            test.h
        
        FORMS += \
            dialog.ui \
            mainwindow.ui \
            test.ui
        
        # Default rules for deployment.
        qnx: target.path = /tmp/$${TARGET}/bin
        else: unix:!android: target.path = /opt/$${TARGET}/bin
        !isEmpty(target.path): INSTALLS += target
        
        

        It seems that my problem is not tremendously relative to camelCase.
        In comment (1), It was signaled that these flag have been append the variable "QMAKE_CXX_FLAGS" in term of function message. However, In comment (2), these flags which are appended in function AddCompilerOptions are not printed.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Silent_Alex
          wrote on last edited by
          #4

          Update:
          The warning 'addCompilerOptions' is not a recognized test function.' has been solved by myself in term of the change to code in following section:

          QT       += core gui
          
          greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
          
          CONFIG += c++17
          
          QMAKE_CXXFLAGS += /std:c++17
          
          defineReplace(addCompilerOptions){
          
              for(compileOption,ARGS){
                  QMAKE_CXXFLAGS += $$compileOption
              }
          
              QMAKE_CXXFLAGS += $$ARGS
              return($$ARGS)
          }
          <----------------Changes------------->
          testFlag=/openmp /fp:fast /diagnostics:care
          
          k=$$addCompilerOptions($$testFlag)
          <----------------Changes------------->
          
          message($$quote(The option of compile $$QMAKE_CXXFLAGS))
          
          # The following define makes your compiler emit warnings if you use
          # any Qt feature that has been marked deprecated (the exact warnings
          # depend on your compiler). Please consult the documentation of the
          # deprecated API in order to know how to port your code away from it.
          DEFINES += QT_DEPRECATED_WARNINGS
          
          include(test_a/test_a.pri)
          
          f=quote(I like your)
          k=quote(like)
          
          str_a=$$str_member($$k,0,$$num_add($$str_size($$f),-1))
          
          message("The size of Str: $$k ")
          
          # You can also make your code fail to compile if it uses deprecated APIs.
          # In order to do so, uncomment the following line.
          # You can also select to disable deprecated APIs only up to a certain version of Qt.
          #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
          
          SOURCES += \
              dialog.cpp \
              main.cpp \
              mainwindow.cpp \
              test.cpp
          
          HEADERS += \
              dialog.h \
              mainwindow.h \
              test.h
          
          FORMS += \
              dialog.ui \
              mainwindow.ui \
              test.ui
          
          # Default rules for deployment.
          qnx: target.path = /tmp/$${TARGET}/bin
          else: unix:!android: target.path = /opt/$${TARGET}/bin
          !isEmpty(target.path): INSTALLS += target
          
          

          However, there is no any effect to variable QMAKE_CXXFLAGS outside scope of addCompilerOptions.

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

            Because it's not how you should use it. As the documentation explains: "this type of function should be used on the right-hand side of assignments (that is, as an operand)."

            QMAKE_CXXFLAGS += /std:c++17
            QMAKE_CXXFLAGS = $$addCompilerOptions(your_list_of_options)
            

            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

            • Login

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