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
Forum Updated to NodeBB v4.3 + New Features

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 2 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.
  • M Offline
    M Offline
    ManiRon
    wrote on 11 Sept 2018, 05:05 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
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 11 Sept 2018, 06:23 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(:^

      M 1 Reply Last reply 11 Sept 2018, 06:53
      1
      • S sierdzio
        11 Sept 2018, 06:23

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

        MyVariable="some value"
        
        # Then use it:
        message("Variable: "$$MyVariable)
        
        M Offline
        M Offline
        ManiRon
        wrote on 11 Sept 2018, 06:53 last edited by ManiRon 9 Nov 2018, 06:55
        #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)
        }

        S 1 Reply Last reply 11 Sept 2018, 07:00
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 11 Sept 2018, 06:57 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
          • M ManiRon
            11 Sept 2018, 06:53

            @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)
            }

            S Offline
            S Offline
            sierdzio
            Moderators
            wrote on 11 Sept 2018, 07:00 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(:^

            M 1 Reply Last reply 11 Sept 2018, 07:03
            2
            • S sierdzio
              11 Sept 2018, 07:00

              @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.

              M Offline
              M Offline
              ManiRon
              wrote on 11 Sept 2018, 07:03 last edited by ManiRon 9 Nov 2018, 07:07
              #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
              • S Offline
                S Offline
                sierdzio
                Moderators
                wrote on 11 Sept 2018, 07:09 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(:^

                M 1 Reply Last reply 11 Sept 2018, 07:20
                3
                • S sierdzio
                  11 Sept 2018, 07:09
                  !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
                  
                  
                  M Offline
                  M Offline
                  ManiRon
                  wrote on 11 Sept 2018, 07:20 last edited by ManiRon 9 Nov 2018, 07:26
                  #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 ?

                  S 1 Reply Last reply 11 Sept 2018, 07:32
                  0
                  • M ManiRon
                    11 Sept 2018, 07:20

                    @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 ?

                    S Offline
                    S Offline
                    sierdzio
                    Moderators
                    wrote on 11 Sept 2018, 07:32 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(:^

                    M 1 Reply Last reply 11 Sept 2018, 07:46
                    0
                    • S sierdzio
                      11 Sept 2018, 07:32

                      @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.

                      M Offline
                      M Offline
                      ManiRon
                      wrote on 11 Sept 2018, 07:46 last edited by ManiRon 9 Nov 2018, 07:47
                      #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
                      }

                      S 1 Reply Last reply 11 Sept 2018, 07:56
                      0
                      • M ManiRon
                        11 Sept 2018, 07:46

                        @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
                        }

                        S Offline
                        S Offline
                        sierdzio
                        Moderators
                        wrote on 11 Sept 2018, 07:56 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(:^

                        M 1 Reply Last reply 11 Sept 2018, 09:16
                        0
                        • S sierdzio
                          11 Sept 2018, 07:56

                          @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?

                          M Offline
                          M Offline
                          ManiRon
                          wrote on 11 Sept 2018, 09:16 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 ?

                          S 1 Reply Last reply 11 Sept 2018, 09:29
                          0
                          • M ManiRon
                            11 Sept 2018, 09:16

                            @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 ?

                            S Offline
                            S Offline
                            sierdzio
                            Moderators
                            wrote on 11 Sept 2018, 09:29 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(:^

                            M 1 Reply Last reply 11 Sept 2018, 09:47
                            0
                            • S sierdzio
                              11 Sept 2018, 09:29

                              @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.

                              M Offline
                              M Offline
                              ManiRon
                              wrote on 11 Sept 2018, 09:47 last edited by
                              #14

                              @sierdzio ok I will try that and say

                              1 Reply Last reply
                              0

                              2/14

                              11 Sept 2018, 06:23

                              topic:navigator.unread, 12
                              • Login

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