After Qt6 is installed, the compilation is normal, but there is a problem with direct operation

Problem Description:

 Create a new mainWindows desktop project, compile it directly, and compile normally. Then ctrl+R to run the program:

 Crashed directly. Prompt about the error:

qt.qpa.plugin: Could not find the Qt platform plugin "windows" in ""
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

The Qt installation path has been moved. It may be a guess of the path problem. According to the online post search reference   copy dependency method.

Try method:

Add the following code to the pro file:

## 加入pro文件,编译后自动复制依赖库进入编译后的目录
contains(CONFIG, static){
    # Static compilation does not require deployment
}else{
    # Windows platform(only for x86 architecture)
    win32 {
        DEPLOY_TOOL = $${dirname(QMAKE_QMAKE)}/windeployqt.exe
        DEPLOY_TOOL = $$replace(DEPLOY_TOOL, /, \\)

        contains(CONFIG, debug, debug|release){
            DEPLOY_TARGET = $${OUT_PWD}/debug/$${TARGET}.exe
        }else{
            DEPLOY_TARGET = $${OUT_PWD}/release/$${TARGET}.exe
        }

        DEPLOY_TARGET=$$replace(DEPLOY_TARGET, /, \\)
        msvc {
            QMAKE_POST_LINK+=$${DEPLOY_TOOL} $${DEPLOY_TARGET} --force --no-translations $$escape_expand(\\n)
        }else{
            QMAKE_POST_LINK+=$${DEPLOY_TOOL} $${DEPLOY_TARGET} --force --no-translations $$escape_expand(\\n\\t)
        }

        CONFIG(debug, debug|release){
            DEPLOY_TARGET_PATH = $$OUT_PWD/debug/
        }
        CONFIG(release, debug|release){
            DEPLOY_TARGET_PATH = $$OUT_PWD/release/
        }
    }
}

Recompile the code, run ctrl+R, and the program runs normally.

The above code explanation is mainly to copy dependencies into the compiled directory, which is equivalent to publishing the program.

Guess you like

Origin blog.csdn.net/u011624093/article/details/122169697