imx6ul運行qml的Qt程序報錯This plugin does not support createPlatformOpenGLContext!
- 1、開發環境
- 2、問題復現
- 3、解決辦法
- 第一種方法
- 第二種方法
- 4、結論
1、開發環境
主板:imx6ul
Qt版本:5.9.6
文件系統:buildroot
問題描述:現需要在現有的文件系統中的Qt環境運行qml程序
2、問題復現
運行一個Qt自帶的例程程序虛擬鍵盤輸入Demo程序:basic
將basic程序交叉編譯后放至imx6ul板子端運行,報以下錯誤:
root@imx6ul:~# ./basic
evdevtouch: /dev/input/event0: Invalid ABS limits, behavior unspecified
This plugin does not support createPlatformOpenGLContext!
Failed to create OpenGL context for format QSurfaceFormat(version 2.0, options QFlags<QSurfaceFormat::FormatOption>(), depthBufferSize 24, redBufferSize -1, greenBufferSize -1, blueBufferSize -1, alphaBufferSize -1, stencilBufferSize 8, samples -1, swapBehavior QSurfaceFormat::SwapBehavior(DoubleBuffer), swapInterval 1, profile QSurfaceFormat::OpenGLContextProfile(NoProfile))
Aborted
這個錯誤大概是由于imx6ul本身是不帶用GPU功能的,所以只能使用linuxfb插件,也就是說軟件渲染。如果是使用qml去編寫程序,需特別注意不能使用到Quick2。
3、解決辦法
1、在Qt源碼編譯的時候,可以增加一個編譯選項-no-opengl,這樣就可以確保編譯之后 不帶有opengl的相關庫,比如QtGraphicalEffects模塊就不會再編譯出來。
第一種方法
./configure -release \-xplatform linux-arm-gnueabi-g++ \-no-dbus \-no-opengl\ //添加此選項-prefix /home/hyb/qt-everywhere-opensource-src-5.9.1/arm-qt \-opensource -confirm-license -make libs \-nomake tools -nomake examples -nomake tests \-skip qt3d -skip qtandroidextras -skip qtcanvas3d \-skip qtconnectivity -skip qtdatavis3d -skip qtdoc \-skip qtgamepad -skip qtimageformats -skip qtlocation \-skip qtmacextras -skip qtmultimedia -skip qtnetworkauth -skip qtpurchasing -skip qtsensors \-skip qtserialbus -skip qtspeech -skip qttools -skip qtwebchannel \-skip qtwebengine -skip qtwebsockets -skip qtwebview -skip qtwinextras \-skip qtx11extras -no-feature-iconv -no-feature-gestures -no-qml-debug \-I/opt/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi/usr/include
第二種方法
如果在第一種方法的前提下不加-no-opengl這個編譯選項的話,在板子端執行大概率會報上述basic運行的錯誤,在查看Qt官網的相關資料,發現可以配置為軟件渲染,通過設置環境變量來實現。
LinuxFB
This plugin writes directly to the framebuffer via Linux’s fbdev subsystem. Only software-rendered content is supported. Note that on some setups the display performance is expected to be limited. To use Qt Quick applications with this platform plugin, the software scenegraph backend must be used, either by setting QT_QUICK_BACKEND=software in the environment, or by calling setGraphicsApi() with QSGRendererInterface::Software. QWidget applications, or QWindow with a surface type of QSurface::RasterSurface, are supported, but this does not include special widgets such as QOpenGLWidget.
export QT_QUICK_BACKEND="software"
4、結論
通過以上方法后,basic的虛擬鍵盤程序就可以正常運行了。