嵌入式 qt 學習筆記


1. stdlib.h not found,原因是頭文件位置沒有設置。

Tools --> options --> kits --> compile 選擇相應的編譯器,然后下面的 Header paths 點擊 后面的 details,填寫頭文件地址,比如: /home/book/100ask_imx6ull-sdk/Buildroot_2019.02/output/host/arm-buildroot-linux-gnueabihf/sysroot/usr/include

2. error: WARNING: unsafe header/library path used in cross-compilation: '-L/usr/lib' qt嵌入式開發,庫需要使用交叉編譯的庫。

在 pro 文件中,加入下面這樣的:

LIBS += \
        -L/home/book/libarmhf -ltoupcam \

3. qt 輸出信息到 console

projects --> run --> Run in terminal
然后在 pro 文件中,增加 CONFIG += console
最后在源文件中,直接使用 qDebug() 就可以輸出到 console 了。

參考: https://blog.csdn.net/yizhou2010/article/details/52996673

4. qpixmap fromImage 缺省參數無效。

原因是相應的頭文件找不到,或者配置不對。
在 pro 文件里面增加:

INCLUDEPATH += /home/book/100ask_imx6ull-sdk/Buildroot_2019.02/output/host/opt/ext-toolchain/arm-linux-gnueabihf/include/c++/6.2.1
INCLUDEPATH += /home/book/100ask_imx6ull-sdk/Buildroot_2019.02/output/host/opt/ext-toolchain/arm-linux-gnueabihf/include/c++/6.2.1/arm-linux-gnueabihf

然后會提示 stubs.h 找不到 stubs-soft.h。 經過查找,只有 stubs-hard.h,這個是硬件浮點運算。但是 qt 當中找不到 寫相應 預編譯 指令的地方。嘗試修改兩個地方,就可以了。
pro 文件。

QMAKE_CXXFLAGS += -mfloat-abi=hard
QMAKE_CFLAGS += -mfloat-abi=hard

stubs.h 文件

#define __ARM_PCS_VFP

這下相關的函數,就可以正常使用了。

5. 普通類轉變為 繼承 QObject 的子類,必須 rebuild all,讓 qmake 重新運行,否則會一直報錯。

6. qt5 的槽 可以不用寫 slots。 只要寫出 signals.

7. 第三方驅動中 so 文件放在 /usr/lib 下就可以,交叉編譯的庫需要另外放一個文件夾,然后編譯的時候,增加路徑即可。

參考: https://www.169it.com/tech-qa-linux/article-224882342649989428.html

8. video0 找不到,首先使用 dmesg | grep usb 來看看 usb 里面有沒有 camera 的信息。然后 lsusb 來看看具體幾個 usb。通過對比 http://www.ideasonboard.org/uvc/ 看看自己的攝像頭是不是 uvc 攝像頭。

具體參考: https://blog.csdn.net/weixin_43262513/article/details/88073532

9. qt 中 使用 QImage 顯示圖像: 如果是 RGB888, 24位存儲數據。

       QImage img(640,480,QImage::Format_RGB888);//24位
        unsigned char * p_bits=img.bits();
        for(int i=0;i<640*480*3;i+=3)
    {
        puiBits[i]=data[i];
        puiBits[i+1]=data[i+1];
        puiBits[i+2]=data[i+2];
    }
    QPixmap pixmap=QPixmap::fromImage(img);
    pixmap=pixmap.scaled(widget->size());
    widget->setAutoFillBackground(true);
    QPalette palette;
    palette.setBrush(widget->backgroundRole(), QBrush(pixmap));
    widget->setPalette(palette);
    widget->repaint();

也可以把其中填充數據的地方改為:

    for (int y = 0; y < img->height(); y++) {
        memcpy(img->scanLine(y), buf + img->bytesPerLine() * y, img->bytesPerLine());
    }

具體參考: https://www.cnblogs.com/muyuhu/archive/2012/10/31/2748361.html
https://stackoverflow.com/questions/14563180/raw-data-to-qimage

10. 基於 QCamera 的一些使用可以參考:

https://blog.csdn.net/Sun_tian/article/details/88063382
https://blog.csdn.net/ACK_ACK/article/details/99799092

11. qt 圖片縮放。

平滑縮放:
ui->label->setPixmap(QPixmap::fromImage(*img).scaled(ui->label->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));

可以使用兩級縮放,第一次快速縮放到最終大小的4倍,第二次平滑縮放,這樣處理又快又好。
QImage result = img.scaled(800, 600).scaled(200, 150, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);

參考: http://blog.sina.com.cn/s/blog_73f981750102uwxj.html
https://blog.csdn.net/kfy2011/article/details/77867609
https://www.cnblogs.com/s_agapo/archive/2012/03/14/2395603.html
https://blog.csdn.net/keanight/article/details/79150637

12. github 中有一個 toupcam 的代碼,可以參考:

https://github.com/JohnDMcMaster/gst-plugin-toupcam

13. usb camera 驅動移植參考:

https://www.cnblogs.com/alan666/p/8311898.html

14. qtcreator 增加 幫助

參考: https://blog.csdn.net/ruglcc/article/details/7996183

還可以安裝對應的新版的 qtcreator.
參考: https://blog.csdn.net/L_0x0b/article/details/105965494

15. qtcreator 配置:

kits --> compile --> manual --> c --> custom 里面設置

compile path: /home/book/100ask_imx6ull-sdk/Buildroot_2019.02/output/host/bin/arm-linux-gnueabihf-gcc
make path: /usr/bin/make
abi: arm, linux, generic, elf, 32bit
macros: mfloat-abi=hard
header path: /home/book/100ask_imx6ull-sdk/Buildroot_2019.02/output/host/arm-buildroot-linux-gnueabihf/sysroot/usr/include

kits --> compile --> manual --> c++ --> custom 里面設置

compile path: /home/book/100ask_imx6ull-sdk/Buildroot_2019.02/output/host/bin/arm-linux-gnueabihf-g++
make path: /usr/bin/make
abi: arm, linux, generic, elf, 32bit
macros: mfloat-abi=hard
header path: /home/book/100ask_imx6ull-sdk/Buildroot_2019.02/output/host/arm-buildroot-linux-gnueabihf/sysroot/usr/include

kits --> qt version --> manual 里面設置

version name: Qt %{Qt:Version} (host)
qmake location: /home/book/100ask_imx6ull-sdk/Buildroot_2019.02/output/host/bin/qmake

kits --> manual 里面設置

name: 100ask_imx6ull
device type: desktop
device: local pc
sysroot: /home/book/100ask_imx6ull-sdk/Buildroot_2019.02/output/host/bin
c: custom
c++: custom
debugger: system gdb
qt version: 5.14.2

16. qtcreator 沒有幫助信息,最簡單的解決方法是安裝新版的 qtcreator,新版的 qtcreator 自帶源碼和幫助。

參考: https://blog.csdn.net/L_0x0b/article/details/105965494


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM