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. External program gives std::bad_alloc()
QtWS25 Last Chance

External program gives std::bad_alloc()

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 747 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.
  • H Offline
    H Offline
    Hollow10
    wrote on 5 Dec 2022, 10:17 last edited by
    #1

    I have an external project that I want to run within QT using a .bat file. The compilation is entirely separate from the QT project, when I run the project externally it works fine with no errors, but if I run it from my QT project (during run time) it gives me a memory error.
    I've used system(), QProcess::execute(), QProcess::start(), QProcess::startDetached() but nothing seems to work. One thing to note is that when compiling I get a missing <GL/freeglut.h> header file, even though I don't get this error when I compile externally.

    J 1 Reply Last reply 5 Dec 2022, 10:21
    0
    • H Hollow10
      5 Dec 2022, 10:17

      I have an external project that I want to run within QT using a .bat file. The compilation is entirely separate from the QT project, when I run the project externally it works fine with no errors, but if I run it from my QT project (during run time) it gives me a memory error.
      I've used system(), QProcess::execute(), QProcess::start(), QProcess::startDetached() but nothing seems to work. One thing to note is that when compiling I get a missing <GL/freeglut.h> header file, even though I don't get this error when I compile externally.

      J Offline
      J Offline
      JonB
      wrote on 5 Dec 2022, 10:21 last edited by JonB 12 May 2022, 10:22
      #2

      @Hollow10
      Hello and welcome.

      One possibility is that your host genuinely does not have enough free memory when Qt Creator (and your calling program) is in memory and hence the sub-process has insufficient memory. Have a look at free memory before you spawn the sub-process.

      In principle running via QProcess or system() in themselves should have no relevance.

      I would also sort out whatever you are saying about an include file not being found in some circumstances. However, that is a compile-time thing, it does not affect runtime.

      1 Reply Last reply
      0
      • H Offline
        H Offline
        Hollow10
        wrote on 5 Dec 2022, 10:45 last edited by Hollow10 12 May 2022, 10:55
        #3

        Hi, thanks for the quick reply.
        I really doubt that my host is incapable of running both processes, I just checked and it's in no way near running out of memory.
        I added the following line to the .pro file 'QMAKE_CXXFLAGS += -Wl,--large-address-aware' but it doesn't seem to make that much of a difference either.
        I also changed my kit's compiler to match mingw's (the one I'm using externally), it did seem to get rid of the library problem but the memory error is still persistent. Thank you for your time.

        J 1 Reply Last reply 5 Dec 2022, 12:54
        0
        • H Hollow10
          5 Dec 2022, 10:45

          Hi, thanks for the quick reply.
          I really doubt that my host is incapable of running both processes, I just checked and it's in no way near running out of memory.
          I added the following line to the .pro file 'QMAKE_CXXFLAGS += -Wl,--large-address-aware' but it doesn't seem to make that much of a difference either.
          I also changed my kit's compiler to match mingw's (the one I'm using externally), it did seem to get rid of the library problem but the memory error is still persistent. Thank you for your time.

          J Offline
          J Offline
          JonB
          wrote on 5 Dec 2022, 12:54 last edited by
          #4

          @Hollow10
          Then it looks like you have an external program which sometimes generates bad_alloc(). For unknown reasons this seems to occur when run from your Qt program, that might be "coincidence". That is going to be pretty hard to track down. It is the external program which generates the bad_alloc(), not your Qt program which spawns it, right?

          H 1 Reply Last reply 6 Dec 2022, 09:38
          0
          • K Offline
            K Offline
            Kent-Dorfman
            wrote on 5 Dec 2022, 17:19 last edited by
            #5

            in the linux world this would be explained by child inheriting restricting ulimit values from the parent. In windoze, I have no clue.

            freeglut is an open source opengl ui library. your Qt project build isn't including the header when you compile internally.

            1 Reply Last reply
            0
            • H Offline
              H Offline
              Hollow10
              wrote on 6 Dec 2022, 08:59 last edited by Hollow10 12 Jun 2022, 08:59
              #6

              @Kent-Dorfman Correct. I also went out of my way to link the library to the project but still nothing. Like I said previously changing QT's compiler seems to get rid of the error when the external compilation happens. I'm assuming QT forces its own compiler selected in the kit when running external scripts that have absolutely nothing to do with the project, correct me if I'm wrong.

              J 1 Reply Last reply 6 Dec 2022, 09:08
              0
              • H Hollow10
                6 Dec 2022, 08:59

                @Kent-Dorfman Correct. I also went out of my way to link the library to the project but still nothing. Like I said previously changing QT's compiler seems to get rid of the error when the external compilation happens. I'm assuming QT forces its own compiler selected in the kit when running external scripts that have absolutely nothing to do with the project, correct me if I'm wrong.

                J Offline
                J Offline
                JonB
                wrote on 6 Dec 2022, 09:08 last edited by JonB 12 Jun 2022, 09:08
                #7

                @Hollow10 said in External program gives std::bad_alloc():

                when the external compilation happens. I'm assuming QT forces its own compiler selected

                I am lost as to where "compilation" is involved/implicated in your issue. You are running an external program and that is throwing a bad_alloc(). I don't see how compilation, or anything about your Qt program which spawns the subprogram, is at issue.

                Also, fyi, when you talk about "QT's compiler" or "Qt forces compiler" you are talking about the Qt Creator IDE, where you edit, build and optionally run your application from. That is not "Qt". Qt is a library of C++ classes which you include into and link against your own Qt application.

                1 Reply Last reply
                0
                • J JonB
                  5 Dec 2022, 12:54

                  @Hollow10
                  Then it looks like you have an external program which sometimes generates bad_alloc(). For unknown reasons this seems to occur when run from your Qt program, that might be "coincidence". That is going to be pretty hard to track down. It is the external program which generates the bad_alloc(), not your Qt program which spawns it, right?

                  H Offline
                  H Offline
                  Hollow10
                  wrote on 6 Dec 2022, 09:38 last edited by Hollow10 12 Jun 2022, 09:39
                  #8

                  @JonB I'm truly sorry for the lack of clarification. I was indeed talking about QT Creator IDE. Now that that's out of the way I want to clarify how my external program/shell works. it's a .bat file that compiles and then run an external project. I only execute the .bat file from QT.
                  When I run the .bat file manually it compiles and runs the external project flawlessly.

                  Here's a quick run of the errors I encountered and the things I tried:

                  When run from QT, it gives me a compile-time error (missing header) followed by a runtime error (memory error) - to be more specific, the external program crashes and then throws a bad_alloc().

                  When changing the QT Creator IDE's kit compiler (to mingw's), matching my system's compiler, I no longer get compiling errors but I still get the memory error.

                  Compiling the program externally and only running it from QT still gives me the memory error.

                  I appreciate everyone's help, sorry for my lack of clarity earlier.

                  J 1 Reply Last reply 6 Dec 2022, 09:53
                  0
                  • H Hollow10
                    6 Dec 2022, 09:38

                    @JonB I'm truly sorry for the lack of clarification. I was indeed talking about QT Creator IDE. Now that that's out of the way I want to clarify how my external program/shell works. it's a .bat file that compiles and then run an external project. I only execute the .bat file from QT.
                    When I run the .bat file manually it compiles and runs the external project flawlessly.

                    Here's a quick run of the errors I encountered and the things I tried:

                    When run from QT, it gives me a compile-time error (missing header) followed by a runtime error (memory error) - to be more specific, the external program crashes and then throws a bad_alloc().

                    When changing the QT Creator IDE's kit compiler (to mingw's), matching my system's compiler, I no longer get compiling errors but I still get the memory error.

                    Compiling the program externally and only running it from QT still gives me the memory error.

                    I appreciate everyone's help, sorry for my lack of clarity earlier.

                    J Offline
                    J Offline
                    JonB
                    wrote on 6 Dec 2022, 09:53 last edited by
                    #9

                    @Hollow10 said in External program gives std::bad_alloc():

                    When run from QT, it gives me a compile-time error (missing header) followed by a runtime error (memory error) - to be more specific, the external program crashes and then throws a bad_alloc().

                    If you have a "compile-time error (missing header)" that means/should mean that the compilation is aborted. No linking is performed, and no executable is generated. If the .bat file still continues and runs some executable, then it cannot be an executable generated just now, it can only (presumably) be some executable left over from some previously run successful compile+link?

                    At a guess, changing compilers/kits in Qt Creator might put some variables into the environment for the target compiler/kit. These might be inherited when you run that executable from Creator, and might affect the compilation it performs. That's all I can think of.

                    Start out, I think, by ensuring that the compilation/link is identical whether performed from within Creator or outside it. Then you know you are building the same executable either way.

                    I still don't know why you get a bad_alloc when you run the built executable inside versus outside Qt Creator. It could be "coincidence", e.g. a fault is there but it only shows up in certain circumstances. You might test running some other executable from your Qt application to verify that works without the bad_alloc error. You should also check in your various compilations whether you are building for debug or release.

                    1 Reply Last reply
                    0

                    4/9

                    5 Dec 2022, 12:54

                    • Login

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