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. QProcess - starting Java app - wrong environment?
Forum Updated to NodeBB v4.3 + New Features

QProcess - starting Java app - wrong environment?

Scheduled Pinned Locked Moved General and Desktop
12 Posts 2 Posters 6.3k 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.
  • V Offline
    V Offline
    viktor.benei
    wrote on 7 Mar 2012, 19:36 last edited by
    #1

    I have to start a Java application.

    I tried with the usual QProcess solution:

    @QProcess process;

        if(!workingDir.isEmpty()) {
            process.setWorkingDirectory(workingDir);
        }
        process.start(appPath, args, QProcess::ReadOnly);
        process.waitForFinished(50000);
    
        DLog("Std out: ") << process.readAllStandardOutput();
        DLog("Std error: ") << process.readAllStandardError();@
    

    The Java app starts, but I have a problem with it:
    if I run the app "java" with the arg "-version" it prints that the java version is "java version "1.6.0_29"" although I installed 1.6.0_31, and even restarted my Windows 7. Also if I open up a command line and type in "java -version" it prints the new 1.6.0_31 version, but not from any Qt app (I've made test apps and all prints the "1.6.0_29" version).

    How could I solve this problem?
    Thanks in advance.

    My dev machine:
    Win 7 x64, Qt 4.7.4, MSVC 2008

    1 Reply Last reply
    0
    • V Offline
      V Offline
      viktor.benei
      wrote on 7 Mar 2012, 19:38 last edited by
      #2

      I also tested it with MinGW, Qt 4.8.4 - I've got the same issue.

      1 Reply Last reply
      0
      • I Offline
        I Offline
        Iktwo
        wrote on 7 Mar 2012, 19:40 last edited by
        #3

        Did you set the _29 version in PATH (enviroment variable)? maybe you have it there..

        how are you lauching the app? I mean what's in appPath?

        1 Reply Last reply
        0
        • V Offline
          V Offline
          viktor.benei
          wrote on 7 Mar 2012, 19:54 last edited by
          #4

          Thanks for the quick reply.

          As I mentioned I can start the app on my machine, that's not a problem (to answer your question: in case I want to run a Java app the appPath is "java" and the args are: "-jar" "the-java-app-path", and it starts the app).

          I'm concerned about the wrong Java version -> I tested that with appPath = "java" and args containing only 1 arg: "-version". In this case it prints the wrong version (_29) - and if I type it directly to a command line ("java -version") it prints the correct version (_31).

          [quote author="Iktwo" date="1331149229"]Did you set the _29 version in PATH (enviroment variable)? maybe you have it there..

          how are you lauching the app? I mean what's in appPath?[/quote]

          1 Reply Last reply
          0
          • I Offline
            I Offline
            Iktwo
            wrote on 7 Mar 2012, 19:59 last edited by
            #5

            I understand the problem, but it seems you have installed two versions, it's weird that if you open up a command line and type in “java -version” it prints the new 1.6.0_31 version, that's why I wanted to know how are you launching your app and what's in your PATH variable, maybe you added both versions to PATH? I don't know what happens if you do that, let me try and see what I get

            1 Reply Last reply
            0
            • V Offline
              V Offline
              viktor.benei
              wrote on 7 Mar 2012, 20:21 last edited by
              #6

              That's exactly I'm concerned about: why do I get different versions from command line and from a Qt app. I have to make it work on any system - the client app (Qt app ;) ) checks the installed Java version and installs a new version if required. But after the newer version is installed I still get the old java version from my Qt app although when I print the version from command line I get the correct, new version.

              In case no Java version is installed and my app installs the required Java version everything works fine, even without restarting the app. But if there's a previously installed Java version the app gets the wrong version, even if I restart the whole OS.

              I checked the PATH and there's no Java related item in it.

              BUT! I found 2 different Java versions in my machine! 1 in "Program Files (x86)\Java" and another one in "Program Files\Java". The (x86) contains the wrong _29 version and the "Program Files\Java" contains the _31 version.

              I also found a Java related Environment Variable: QTJAVA which points to the wrong dir (the "Program Files (x86)\Java" one). I don't even know why this entry sits in the Env. Vars. (I don't use any Qt-Java binding, the app is pure C++/Qt) but probably this one causes the problem.

              1 Reply Last reply
              0
              • I Offline
                I Offline
                Iktwo
                wrote on 7 Mar 2012, 20:30 last edited by
                #7

                Oh, so you have installed both x64 and x86 versions, that may be the problem, but still I don't understand why are you getting different outputs, I don't know if windows have different environment variables for x86 apps and x64, I think that because you said you get _29 from Qt, and that's the one for 32bit and the _31 it's the 64, so if there are two PATH variables Qt it's loading the x86 PATH

                look at this it may help
                http://superuser.com/questions/247614/different-path-environment-variable-for-32bit-and-64bit-windows-is-it-possible

                1 Reply Last reply
                0
                • V Offline
                  V Offline
                  viktor.benei
                  wrote on 7 Mar 2012, 20:32 last edited by
                  #8

                  I think I'm getting closer...

                  If I'm right the problem is this:
                  My development machine is a 64 bit Win 7, but my Qt app is 32 bit. It detects that the system is 64 bit so it will install the 64 bit Java runtime - but a 32 bit version (the _29 in the "Program Files (x86)" folder) is also installed and I think because the app is 32 bit it will get the 32 bit Java when it starts a Java app.

                  1 Reply Last reply
                  0
                  • V Offline
                    V Offline
                    viktor.benei
                    wrote on 7 Mar 2012, 20:36 last edited by
                    #9

                    Sorry for the answer duplication, I didn't notice you've already posted your answer.

                    So I guess the solution in my case will be to install the 32 bit java runtime even in a 64 bit machine and that should work.

                    Thanks for your time!

                    1 Reply Last reply
                    0
                    • I Offline
                      I Offline
                      Iktwo
                      wrote on 7 Mar 2012, 20:38 last edited by
                      #10

                      That's probably it, I'm gonna search more info about it, hope you work it out :)

                      1 Reply Last reply
                      0
                      • V Offline
                        V Offline
                        viktor.benei
                        wrote on 7 Mar 2012, 20:39 last edited by
                        #11

                        Thanks, in case I find a better solution I'll definitely post it here :)

                        1 Reply Last reply
                        0
                        • V Offline
                          V Offline
                          viktor.benei
                          wrote on 7 Mar 2012, 21:44 last edited by
                          #12

                          For those who face the same problem:

                          If you start a java application with QProcess it will start java with the same bitness of the Qt app!

                          It means: if your Qt app is 32 bit and you run it on a 64 bit Windows it won't find the 64 bit Java, even if there's no 32 bit Java installed only the 64 bit! It will only find the 32 bit Java (if installed)!

                          1 Reply Last reply
                          0

                          1/12

                          7 Mar 2012, 19:36

                          • Login

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