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. Can i store a value in a variable in QT .PRO file

Can i store a value in a variable in QT .PRO file

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 3 Posters 2.1k Views
  • 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.
  • ManiRonM Offline
    ManiRonM Offline
    ManiRon
    wrote on last edited by
    #1

    is there any way that i can create a variable in QT .PRO file and use it .

    For Example : i want to check whether QMAKESPEC contains certain text (i.e) win32-g++ and run a library

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      You can create variables in qmake the same way you do it in shell:

      MyVariable="some value"
      
      # Then use it:
      message("Variable: "$$MyVariable)
      

      (Z(:^

      ManiRonM 1 Reply Last reply
      1
      • sierdzioS sierdzio

        You can create variables in qmake the same way you do it in shell:

        MyVariable="some value"
        
        # Then use it:
        message("Variable: "$$MyVariable)
        
        ManiRonM Offline
        ManiRonM Offline
        ManiRon
        wrote on last edited by ManiRon
        #3

        @sierdzio

        ok sir,

        Now i want to check for "win32-g++" in this string "C:/Qt/Qt5.5.0/5.5/mingw492_32/mkspecs/win32-g++"

        How can i do that?

        i tried like this

        MyVariable = $$QMAKESPEC
        contains($$MyVariable,win32-g++){
        message(Windows)
        }
        else{
        message(LINUX)
        }

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

          Hi,

          Aren't you rather looking for scope ?

          win32{
          # Windows specific Stuff
          }
          

          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
          3
          • ManiRonM ManiRon

            @sierdzio

            ok sir,

            Now i want to check for "win32-g++" in this string "C:/Qt/Qt5.5.0/5.5/mingw492_32/mkspecs/win32-g++"

            How can i do that?

            i tried like this

            MyVariable = $$QMAKESPEC
            contains($$MyVariable,win32-g++){
            message(Windows)
            }
            else{
            message(LINUX)
            }

            sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #5

            @ManiRon said in Can i store a value in a variable in QT .PRO file:

            contains($$MyVariable,win32-g++){

            Wrong syntax. No $$ is necessary in contains.

            Besides, what @SGaist suggests is indeed the best choice in your case. Scopes work for all values from CONFIG variable, and for makespecs as well.

            (Z(:^

            ManiRonM 1 Reply Last reply
            2
            • sierdzioS sierdzio

              @ManiRon said in Can i store a value in a variable in QT .PRO file:

              contains($$MyVariable,win32-g++){

              Wrong syntax. No $$ is necessary in contains.

              Besides, what @SGaist suggests is indeed the best choice in your case. Scopes work for all values from CONFIG variable, and for makespecs as well.

              ManiRonM Offline
              ManiRonM Offline
              ManiRon
              wrote on last edited by ManiRon
              #6

              @sierdzio actually i am facing some problem

              1. i want to run my application in windows , Linux, Xenomai.
              2. i have separate library for each platform
              3. i want to invoke the library based on the platform i run
              4. I can use win32 and unix for windows and linux
              5. but what should i use for xenomai
              6. if i declare both in unix it throws error

              Any solution? thats why i though of using contains() else method to invoke that particular library by checking win32-g++,linux-g++ and if it not both i will run xenomai library like that i planned

              1 Reply Last reply
              0
              • sierdzioS Offline
                sierdzioS Offline
                sierdzio
                Moderators
                wrote on last edited by
                #7
                !win32:!linux {
                  # Your xenomai libs go here
                }
                

                That should work.

                Alternatively, you can use your own custom config here:

                xenomai {
                  # Your xenomai libs go here
                } else {
                  win32 {
                  }
                  linux {
                  }
                }
                

                Run qmake this way:

                qmake CONFIG+=xenomai
                
                

                (Z(:^

                ManiRonM 1 Reply Last reply
                3
                • sierdzioS sierdzio
                  !win32:!linux {
                    # Your xenomai libs go here
                  }
                  

                  That should work.

                  Alternatively, you can use your own custom config here:

                  xenomai {
                    # Your xenomai libs go here
                  } else {
                    win32 {
                    }
                    linux {
                    }
                  }
                  

                  Run qmake this way:

                  qmake CONFIG+=xenomai
                  
                  
                  ManiRonM Offline
                  ManiRonM Offline
                  ManiRon
                  wrote on last edited by ManiRon
                  #8

                  @sierdzio

                  message($$QMAKESPEC)

                  when i tried to print the project message for linux and windows i got something like this

                  Project MESSAGE: C:/Qt/Qt5.5.0/5.5/mingw492_32/mkspecs/win32-g++ for windows and corresponding for linux.

                  But when i tried the same for xenomai i didnt get any. Is there any way ?

                  sierdzioS 1 Reply Last reply
                  0
                  • ManiRonM ManiRon

                    @sierdzio

                    message($$QMAKESPEC)

                    when i tried to print the project message for linux and windows i got something like this

                    Project MESSAGE: C:/Qt/Qt5.5.0/5.5/mingw492_32/mkspecs/win32-g++ for windows and corresponding for linux.

                    But when i tried the same for xenomai i didnt get any. Is there any way ?

                    sierdzioS Offline
                    sierdzioS Offline
                    sierdzio
                    Moderators
                    wrote on last edited by
                    #9

                    @ManiRon said in Can i store a value in a variable in QT .PRO file:

                    But when i tried the same for xenomai i didnt get any. Is there any way ?

                    If you don't specify a makespec then the variable will be empty. You can create your own mkspecs if you want to (they are stored in Qt directory and are simple text files), but I'd rather recommend using a predefined one. Does your platform come with some toolchain / precompiled Qt version? Then it should have some makespecs defined already.

                    But the simplest solution is just to use one of the conditions I mentioned in my previous post.

                    (Z(:^

                    ManiRonM 1 Reply Last reply
                    0
                    • sierdzioS sierdzio

                      @ManiRon said in Can i store a value in a variable in QT .PRO file:

                      But when i tried the same for xenomai i didnt get any. Is there any way ?

                      If you don't specify a makespec then the variable will be empty. You can create your own mkspecs if you want to (they are stored in Qt directory and are simple text files), but I'd rather recommend using a predefined one. Does your platform come with some toolchain / precompiled Qt version? Then it should have some makespecs defined already.

                      But the simplest solution is just to use one of the conditions I mentioned in my previous post.

                      ManiRonM Offline
                      ManiRonM Offline
                      ManiRon
                      wrote on last edited by ManiRon
                      #10

                      @sierdzio

                      xenomai {
                      #Your xenomai libs go here
                      } else {
                      win32 {
                      }
                      linux {
                      }
                      }
                      in this it is going to linux when i run in xenomai platform. not tested with this but test like this.
                      linux{
                      #xenomai libs
                      }

                      sierdzioS 1 Reply Last reply
                      0
                      • ManiRonM ManiRon

                        @sierdzio

                        xenomai {
                        #Your xenomai libs go here
                        } else {
                        win32 {
                        }
                        linux {
                        }
                        }
                        in this it is going to linux when i run in xenomai platform. not tested with this but test like this.
                        linux{
                        #xenomai libs
                        }

                        sierdzioS Offline
                        sierdzioS Offline
                        sierdzio
                        Moderators
                        wrote on last edited by
                        #11

                        @ManiRon said in Can i store a value in a variable in QT .PRO file:

                        in this it is going to linux when i run in xenomai platform

                        Because you have not called qmake with CONFIG+=xenomai, right?

                        (Z(:^

                        ManiRonM 1 Reply Last reply
                        0
                        • sierdzioS sierdzio

                          @ManiRon said in Can i store a value in a variable in QT .PRO file:

                          in this it is going to linux when i run in xenomai platform

                          Because you have not called qmake with CONFIG+=xenomai, right?

                          ManiRonM Offline
                          ManiRonM Offline
                          ManiRon
                          wrote on last edited by
                          #12

                          @sierdzio

                          Actually i havent tested with your code . we tested yesterday like

                          linux{
                          Libs of xenomai
                          }
                          we thought it wont go in but it went in . the same we used for xenomai also we oserved the same .

                          One of the person from QT forum told that linux can be given for both linux and xenomai

                          now if this is the case . If i use the code which u mentioned it wont create a problem ?

                          sierdzioS 1 Reply Last reply
                          0
                          • ManiRonM ManiRon

                            @sierdzio

                            Actually i havent tested with your code . we tested yesterday like

                            linux{
                            Libs of xenomai
                            }
                            we thought it wont go in but it went in . the same we used for xenomai also we oserved the same .

                            One of the person from QT forum told that linux can be given for both linux and xenomai

                            now if this is the case . If i use the code which u mentioned it wont create a problem ?

                            sierdzioS Offline
                            sierdzioS Offline
                            sierdzio
                            Moderators
                            wrote on last edited by
                            #13

                            @ManiRon said in Can i store a value in a variable in QT .PRO file:

                            now if this is the case . If i use the code which u mentioned it wont create a problem ?

                            No. Just try it out :-) You can put in some messages inside - then you'll know exactly which way qmake went. I recommend doing that anyway - to help find issues in the future.

                            (Z(:^

                            ManiRonM 1 Reply Last reply
                            0
                            • sierdzioS sierdzio

                              @ManiRon said in Can i store a value in a variable in QT .PRO file:

                              now if this is the case . If i use the code which u mentioned it wont create a problem ?

                              No. Just try it out :-) You can put in some messages inside - then you'll know exactly which way qmake went. I recommend doing that anyway - to help find issues in the future.

                              ManiRonM Offline
                              ManiRonM Offline
                              ManiRon
                              wrote on last edited by
                              #14

                              @sierdzio ok I will try that and say

                              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