본문 바로가기
QT and Symbian

QT Plugins 폴더 Windows 배포 문제

by leo21c 2020. 7. 24.
SMALL

이번에 작업을 하면서 QT가 설치 되지 않는 컴퓨터에서는 DLL을 모두 포함해서 배포를 해서 실행 해도 프로그램이 강제 종료되는 문제가 발생했다.
원인을 파악한 결과 Plugins 폴더를 함께 배포하지 않아서 발생한 것으로 확인 되었다.

그러나 문제는 Plugins 폴더를 실행 파일과 같은 경로에 추가해도 정상 작동을 하지 않는 것이다.
빌드를 할 때 Plugins 폴더 위치가 배포되는 컴퓨터에도 같은 위치에 존재해야만 정상 작동하는 것을 확인 했다.

빌드 할 때 관련 내용이 실행 파일에 포함되기 때문에 문제를 수정하기 위해서는 아래와 같이 소스에 추가를 해야 한다.

QApplication a(argc, argv); 

#if defined(Q_OS_WIN32) //Windows 배포할 때 필요하다. 
    a.addLibraryPath("./plugins");
#endif

위와 같이 LibraryPath를 지정해서 빌드가 되면 문제가 발생하지 않는다.
경로는 실행 파일 아래에 plugins 폴더가 존재한다는 것이다.

<참조> addLibraryPath 함수

https://het.as.utexas.edu/HET/Software/html/deployment-windows.html#qt-plugins

Qt Plugins

Your application may also depend on one or more Qt plugins, such as the JPEG image format plugin or a SQL driver plugin. Be sure to distribute any Qt plugins that you need with your application, and note that each type of plugin should be located within a specific subdirectory (such as imageformats or sqldrivers) within your distribution directory, as described below.

Note: If you are deploying an application that uses QtWebKit to display HTML pages from the World Wide Web, you should include all text codec plugins to support as many HTML encodings possible.

The search path for Qt plugins is hard-coded into the QtCore library. By default, the plugins subdirectory of the Qt installation is the first plugin search path. However, pre-determined paths like the default one have certain disadvantages. For example, they may not exist on the target machine. For that reason, you need to examine various alternatives to make sure that the Qt plugins are found:

If you add a custom path using QApplication::addLibraryPath it could look like this:

Then qApp->libraryPaths() would return something like this:

"C:/customPath/plugins " "C:/Qt/4.8.5/plugins" "E:/myApplication/directory/"

The executable will look for the plugins in these directories and the same order as the QStringList returned by qApp->libraryPaths(). The newly added path is prepended to the qApp->libraryPaths() which means that it will be searched through first. However, if you use qApp->setLibraryPaths(), you will be able to determend which paths and in which order they will be searched.

The How to Create Qt Plugins document outlines the issues you need to pay attention to when building and deploying plugins for Qt applications.

LIST