0

I'm building a program Using Qt Creator 5.12.11 (64 bit).

I just wanna build a simple "hello world" console app program with Qt but after hitting the RUN button it just builds, but it doesn't run the program so I found the "hello_world.exe" file and try to run it but I get a message that says

"The code execution cannot proceed because Qt5Cored.dll was not found. Reinstalling the program may fix this problem."

So I copied and pasted that DLL file and finally it worked but

HOW solve this type of problem forever?

I use windows 10 (✖64)

I've installed Qt5.12.11 at C:\Qt

and this is my config file and source file

also, I'm a newbie in Qt.

QT -= gui

CONFIG += c++11 console
CONFIG -= app_bundle

# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated `before Qt 6.0.0`

SOURCES += \
        main.cpp

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

and source file

#include <QCoreApplication>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    cout<<"Hello";

    return a.exec();
}
drescherjm
  • 10,365
  • 5
  • 44
  • 64
DariushStony
  • 153
  • 8
  • For some reason Qt-Creator is not using your installed kit correctly. I can't help with that as I develop my Qt applications using Visual Studio and CMake instead of Qt-Creator and QMake. – drescherjm Aug 01 '21 at 14:25
  • What happens, if you add " << endl" to the output statement? – Benjamin Bihler Aug 01 '21 at 16:23
  • @BenjaminBihler strangely prints "Hello" on the qt-creator console but *.exe file still doesn't work – DariushStony Aug 01 '21 at 16:53
  • @BenjaminBihler What is the reason for this? – DariushStony Aug 01 '21 at 16:56
  • ***strangely prints "Hello" on the qt-creator console but *.exe file still doesn't work*** Then it did work correctly. If you are trying to execute the program from outside of Qt-Creator then you want the dlls to be in a folder of your PATH environment variable or in the same folder as your executable. Related: [https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order#search-order-for-desktop-applications](https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order#search-order-for-desktop-applications) – drescherjm Aug 01 '21 at 17:31
  • @drescherjm Thanks, But why " << endl" cause this work in Qt-creator?? – DariushStony Aug 01 '21 at 17:57
  • 1
    Probably a duplicate of this: [https://stackoverflow.com/questions/14858262/stdcout-wont-print](https://stackoverflow.com/questions/14858262/stdcout-wont-print) – drescherjm Aug 01 '21 at 18:02
  • You should read about Qt application deployement https://doc.qt.io/qt-5/deployment.html – tunglt Aug 02 '21 at 08:34
  • 1
    Read about "deploying Qt applications on Windows" (ie. bundling all required dynamic libraries with your app - spoiler alert, usually it is not just QtCore.dll but many more libs which are needed, some of them are however present in your OS but will not be present on your clients computers). This question has been asked a million times already. – HiFile.app - best file manager Aug 02 '21 at 10:57

1 Answers1

0

I found the answer here : Which says :

Change:

std::cout << "Hello World!" << std::flush;

you can use either

std::cout << "Hello World!" << std::endl;

or

std::cout << "Hello World!" << std::flush;

endl places as return as expected, while flush outputs the line to console without the return.