Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. [Solved] Runtime error with Mingw, ifstream, Qt Creator
Forum Updated to NodeBB v4.3 + New Features

[Solved] Runtime error with Mingw, ifstream, Qt Creator

Scheduled Pinned Locked Moved Qt Creator and other tools
11 Posts 3 Posters 7.5k 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi and welcome to devnet,

    Are you by any chance getting error 0xc000135 ?

    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
    0
    • J Offline
      J Offline
      jabaa
      wrote on last edited by
      #3

      No, I don't get any error code.

      This works fine:
      @
      #include <fstream>
      #include <iostream>

      class myClass{
      private:
      public:
      myClass(){};
      void doSomething(std::string path){
      //std::string gl;
      };
      };

      int main(){
      myClass myclass;
      myclass.doSomething("text.txt");
      std::ifstream file;
      return 0;
      }

      @

      and this works fine too:

      @
      #include <fstream>
      #include <iostream>

      class myClass{
      private:
      public:
      myClass(){};
      void doSomething(std::string path){
      std::string gl;
      };
      };

      int main(){
      myClass myclass;
      myclass.doSomething("text.txt");
      //std::ifstream file;
      return 0;
      }

      @

      but this doesn't work:

      @
      #include <fstream>
      #include <iostream>

      class myClass{
      private:
      public:
      myClass(){};
      void doSomething(std::string path){
      std::string gl;
      };
      };

      int main(){
      myClass myclass;
      myclass.doSomething("text.txt");
      std::ifstream file;
      return 0;
      }
      @

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

        What does your pro file look like ?

        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
        0
        • J Offline
          J Offline
          jabaa
          wrote on last edited by
          #5

          That is the pro file:
          @
          #-------------------------------------------------

          Project created by QtCreator 2014-08-27T16:59:28

          #-------------------------------------------------

          QT += core

          QT -= gui

          TARGET = ifstream
          CONFIG += console
          CONFIG -= app_bundle

          TEMPLATE = app

          SOURCES += main.cpp
          @

          Remember, that the Makefile is ok, since I can use mingw32-make with extern g++ from extern mingw to compile the project.

          gcc version: 4.8.1
          GNU Make 3.82.90

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jabaa
            wrote on last edited by
            #6

            Can you reproduce this problem? I work on two different machines, a laptop and a desktop pc. Both with Win 7 Pro 64 bit. And the error occurs on both systems.

            After inserting another std::string, the following code works fine again.

            @
            #include <iostream>
            #include <fstream>

            class myClass{
            private:
            public:
            myClass(){};
            void doSomething(std::string path){
            std::string gl;
            };
            };

            int main(){
            myClass myclass;
            myclass.doSomething("text.txt");
            std::string path;
            std::ifstream file;
            return 0;
            }
            @

            I don't get it. Absolut senseless.

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

              There is no problem. You are linking to the QtCore library, which doesn't really make sense since you are not using Qt at all. So when starting outside Qt Creator your program can't find QtCore.dll. So you can either follow the Windows Deployment Guide or drop the Qt dependency

              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
              0
              • J Offline
                J Offline
                jabaa
                wrote on last edited by
                #8

                I changed the pro file to
                @
                #-------------------------------------------------

                Project created by QtCreator 2014-08-27T16:59:28

                #-------------------------------------------------

                #QT += core

                QT -= gui

                TARGET = ifstream
                CONFIG += console
                CONFIG -= app_bundle

                TEMPLATE = app

                SOURCES += main.cpp
                @
                Nothing changed. When I start the application from outside Qt, it crashes.

                Since I have other, bigger projects with Qt but without std::ifstream and no error occurs, I am sure, that my system finds the dll's. They are added to the system environment. I even tried Dependency Walker. No problems with dll's.

                Now I tried to apply mingw32-make from Qt folder on the makefile. And everything works fine even with linked Qt libs.

                The problem is Qt Creator. When I compile with Qt Creator, I can't run the application from outside Qt Creator. When I configure Qt Creator to use my Mingw, I can run the application from outside Qt Creator but it crashes, when I run the code from inside Qt Creator.

                The most mysterious fact is, that without std::ifstream everything works fine. I used Qt Creator for many projects without problems. But now I need a file stream and this problem occurs the first time.

                I tried now an older project with Qt gui, message box and other Qt relevant features. Everything is ok. It's really just the ifstream

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  jabaa
                  wrote on last edited by
                  #9

                  I think, that I unterstand the problem. I have two different, incompatible mingw on my system disturbing each other. When I compile the code with Qt Creator, g++ from Qt Creator is used. When I run the code from Qt Creator, the libstdc++-6.dll from Qt Creator is linked. When I run the application from outside Qt Creator, the wrong libstdc++-6.dll is linked.

                  I read on the internet, that the header file for fstream from Qt Creator's mingw are different to other mingw's header files. So the library are different too.

                  I copied the libstdc++-6.dll from Qt Creator into my project folder and everything works. The problem is solved for me. Thanks.

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

                    Having multiple MinGW version on your computer is generally the shortest way to problems. The simple way is to use the version your got with the MinGW package.

                    It's not Qt Creator's MinGW, it's a MinGW version known to work well to build Qt. However, and AFAIK, there's no special modification done.

                    Anyway, glad you got it working.

                    Happy coding !

                    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
                    0
                    • T3STYT Offline
                      T3STYT Offline
                      T3STY
                      wrote on last edited by
                      #11

                      Just for your interest, commenting the line #CONFIG += core like you did will not drop the core module. qmake will include the core and gui modules by default, even if your .pro file is empty. Read more here: http://qt-project.org/doc/qt-5/qmake-project-files.html#declaring-qt-libraries

                      So it's better for you to use CONFIG -= core gui to remove these dependencies.

                      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