Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Calling Environment Variables

Calling Environment Variables

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 2 Posters 3.3k 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.
  • Bernard RouhiB Offline
    Bernard RouhiB Offline
    Bernard Rouhi
    wrote on last edited by
    #1

    Hi,

    I'm trying to load external environment variables with QML or JavaScript, but I can find any function to do that.

    what I do normally is to clarify the variable in command line like so:

    set MY_PATH="C:/ProjectA"
    

    and if I lunch the python in same command line I can call the variable like so:

    >>> import os
    >>> print os.environ.get("MY_PATH")
    C:/ProjectA
    

    but now I'm trying to do the same thing in Substance Painter and they only support QML and JavaScript but not C++.
    Is there any way that I can call the OS environment variables in JS or QML?

    A 1 Reply Last reply
    0
    • Bernard RouhiB Bernard Rouhi

      Hi,

      I'm trying to load external environment variables with QML or JavaScript, but I can find any function to do that.

      what I do normally is to clarify the variable in command line like so:

      set MY_PATH="C:/ProjectA"
      

      and if I lunch the python in same command line I can call the variable like so:

      >>> import os
      >>> print os.environ.get("MY_PATH")
      C:/ProjectA
      

      but now I'm trying to do the same thing in Substance Painter and they only support QML and JavaScript but not C++.
      Is there any way that I can call the OS environment variables in JS or QML?

      A Offline
      A Offline
      ambershark
      wrote on last edited by
      #2

      @Bernard-Rouhi I would get the environment variable on the c++ side and pass it to qml.

      Unfortunately if you are on client-side java script there is no way to access environment variables. Which is probably a good thing for the massive security problems that would create. :)

      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

      Bernard RouhiB 1 Reply Last reply
      3
      • A ambershark

        @Bernard-Rouhi I would get the environment variable on the c++ side and pass it to qml.

        Unfortunately if you are on client-side java script there is no way to access environment variables. Which is probably a good thing for the massive security problems that would create. :)

        Bernard RouhiB Offline
        Bernard RouhiB Offline
        Bernard Rouhi
        wrote on last edited by
        #3

        @ambershark Thank you for the reply, I agree with you, but Substance Painter doesn't support C++, according to their documentation, "The plugin are wrote in Javascript and can be combined with the QML language to create custom interface inside the application." Link.

        Is there anyway that I can execute Command line or python file from JS/QML and get the return value?

        A 1 Reply Last reply
        1
        • Bernard RouhiB Bernard Rouhi

          @ambershark Thank you for the reply, I agree with you, but Substance Painter doesn't support C++, according to their documentation, "The plugin are wrote in Javascript and can be combined with the QML language to create custom interface inside the application." Link.

          Is there anyway that I can execute Command line or python file from JS/QML and get the return value?

          A Offline
          A Offline
          ambershark
          wrote on last edited by
          #4

          @Bernard-Rouhi I don't think so. That would have the same security problems. I'm no expert in qml or js but I don't think you can do that.

          Node.js supports getting environment variables but that is a different beast altogether.

          My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

          Bernard RouhiB 1 Reply Last reply
          1
          • A ambershark

            @Bernard-Rouhi I don't think so. That would have the same security problems. I'm no expert in qml or js but I don't think you can do that.

            Node.js supports getting environment variables but that is a different beast altogether.

            Bernard RouhiB Offline
            Bernard RouhiB Offline
            Bernard Rouhi
            wrote on last edited by Bernard Rouhi
            #5

            @ambershark thanks for the reply again, I have noticed that the Substance Painter doesn't compile my QML and JavaScript, and that would be the reason I couldn't link C++ to my QML plugin.

            However, I found that there is a workaround, I can run Substance Painter 2.exe on command line along multiple variables and then call them by using application.arguments

            Example:
            in the command line I go into Substance Painter 2 directory and type:

            "Substance Painter 2.exe" C:/ProjectA
            

            and in my QML plugin I use:

            Qt.application.arguments
            

            and it will return:

            {
              "0": "Substance Painter 2.exe",
              "1": "ProjectA"
            }
            

            This is not a very smart way, but at least lead to some result.

            I'm wondering if there is any way that I can write what I need in C++ and compile it with Qt Creative and add it to the Substance Painter's QML library, but I'm not sure if it's a good idea.

            1 Reply Last reply
            2

            • Login

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