Important: Please read the Qt Code of Conduct -

Problems with <bits/stdc++.h>

  • I have just started learning the Qt framework, and have got the basics of what I want running. Now, I would like to reuse code from 'normal' c++ in a new header file. This code utilized the standard library so I included <bits/stdc++.h>. When I try to include this in my Qt code however, I get an error when attempting to build my project:

    no matching function for call to 'std::filesystem::__cx11::path::path(const string_type&)'

    I seem to have kind of fixed the problem by manually copying and pasting the include of bits/stdc++.h, but clearly this solution is not ideal - does anyone know why this include is not working?

    (Windows 10)

  • What mingw version are you using in Qt?

    Check your kits in your project. You may have to manually add the mingw compiler that enables you to use the std::filesystem for example.

    Also, Qt has its own "everything" standard C++ has. Check the Qt equivalent of std::filesystem.

  • I think I am using 'mingw810_64'; at least, that is what is showing up in the error. How would I add the correct compiler?

  • @Aditya-Gupta mingw810_64 doesn't have std::filesystem.

    How would I add the correct compiler?

    Go to Tool > Options > Kits > Compilers Tab, there's an add button in the right top corner.

  • Lifetime Qt Champion

    @Aditya-Gupta hi and welcome to devnet,

    What exactly are you using from the standard library ?
    Usually you don't directly include the bits headers but the one matching the parts you want to use.

    @hbatalha said in Problems with <bits/stdc++.h>:

    Also, Qt has its own "everything" standard C++ has. Check the Qt equivalent of std::filesystem.

    That's wrong, Qt does not have everything the std has although it has helped shape some elements from the standard. In any case, there's QFile and QDir that where there long before the std::filesystem library.

  • I'm trying to build a GUI for a previous project I had built with standard c++, and am principally using <algorithm>, <vector>, <map> and maybe a few others. More than anything I'd like to know how to include bits/stdc++.h for the future, but for the moment I am just including the files I need separately.

  • Lifetime Qt Champion

    That's the correct way to do it. Include only what you use.

    Also, AFAIK, that bits header is GCC specific so you'll end up with other issues of portability.

  • Moderators

    As @SGaist mentioned this header is a non-standard addition of GCC/MinGW and it basically includes everything from std. Can be useful in large projects to optimize compilation times when used in a precompiled header, but otherwise you should avoid it and include only what you actually use from the standard, portable headers.

    The specific problem here is that one of the headers included here is <filesystem> which has a bug you see in this version of MinGW. Your options are to upgrade to newer MinGW (this issue is supposedly fixed in version 9) or just don't use that header, which I would suggest.

  • as the others don't include bits/{anything}. that directory is for platform specific internal headers that are only to be called by the generic platform independent abstractions. Furthermore, convention is that the parts of the stdlib that have been made available to c++ don't end with .h they are c{headername}, not {headername}.h ... iow, no extension at all in the filename.

Log in to reply