QT程序交叉编译

简介: qte终于移植成功,但是在交叉编译自己写的程序是总是提示有错误,错误如下:In file included from main.cpp:3:./database.

qte终于移植成功,但是在交叉编译自己写的程序是总是提示有错误,错误如下:In file included from main.cpp:3:
./database.h:3:23: QSqlDatabase: No such file or directory
./database.h:4:20: QSqlQuery: No such file or directory
In file included from main.cpp:3:
./database.h: In function `bool createConnection()':
./database.h:8: error: `QSqlDatabase' was not declared in this scope
./database.h:8: error: expected `;' before "db"
./database.h:9: error: `db' was not declared in this scope
./database.h:8: warning: unused variable 'QSqlDatabase'
make: *** [main.o] 错误
提示没有这两个文件或目录?明明在我的include里面怎么会没有?我想尽一切办法,又是该边境变量,又是删除编译文件重新编译,最后还是不行,我一遍一遍的查看include目录,最后发现错误提示的两个文件在include/QtSql/下面所以我就把程序的包含文件目录该了一下原来为:#include<QSqlDatabase>,#include<QSqlQuery>改过后为:#include<QtSql/QSqlDatabase>,#include<QtSql/QSqlQuery>就是在原来的基础上增加一个目录前缀,这样问题就解决了,这个编译通过,但是下面又出现了错误,错误如下:songlist.cpp:6:20: QSqlQuery: No such file or directory
songlist.cpp:12: error: `songlist' has not been declared
songlist.cpp:12: error: ISO C++ forbids declaration of `songlist' with no type
songlist.cpp: In function `int songlist(QWidget*)':
songlist.cpp:12: error: only constructors take base initializers
songlist.cpp:16: error: `ui' was not declared in this scope
songlist.cpp:16: error: invalid use of `this' in non-member function
songlist.cpp:20: error: `model' was not declared in this scope
songlist.cpp:20: error: `QSqlTableModel' has not been declared
songlist.cpp:20: error: invalid use of `this' in non-member function
songlist.cpp:31: error: `model2' was not declared in this scope
songlist.cpp:31: error: `QSqlTableModel' has not been declared
songlist.cpp:31: error: invalid use of `this' in non-member function
songlist.cpp: At global scope:
songlist.cpp:46: error: expected constructor, destructor, or type conversion before '::' token
songlist.cpp:51: error: `songlist' is not a class or namespace
songlist.cpp: In function `void changeEvent(QEvent*)':
songlist.cpp:53: error: cannot call member function `virtual void QWidget::changeEvent(QEvent*)' without object
songlist.cpp:56: error: `ui' was not declared in this scope
songlist.cpp:56: error: invalid use of `this' in non-member function
songlist.cpp:56: warning: unused variable 'ui'
songlist.cpp: At global scope:
songlist.cpp:63: error: `songlist' is not a class or namespace
songlist.cpp: In function `void on_pushButton_clicked()':
songlist.cpp:65: error: `ui' was not declared in this scope
songlist.cpp:70: error: `model' was not declared in this scope
songlist.cpp:80: error: `model2' was not declared in this scope
songlist.cpp:65: warning: unused variable 'ui'
songlist.cpp: At global scope:
songlist.cpp:87: error: `songlist' is not a class or namespace
songlist.cpp: In function `void on_pushButton_4_clicked()':
songlist.cpp:89: error: `ui' was not declared in this scope
songlist.cpp:90: error: `model2' was not declared in this scope
songlist.cpp:92: error: `Dir' was not declared in this scope
songlist.cpp:93: error: `prefix' was not declared in this scope
songlist.cpp:94: error: `PATH' was not declared in this scope
songlist.cpp:97: error: `play1' was not declared in this scope
songlist.cpp:97: warning: unused variable 'play1'
songlist.cpp: At global scope:
songlist.cpp:103: error: `songlist' is not a class or namespace
songlist.cpp: In function `void on_pushButton_3_clicked()':
songlist.cpp:105: error: `ui' was not declared in this scope
songlist.cpp:106: error: `model2' was not declared in this scope
songlist.cpp:105: warning: unused variable 'ui'
songlist.cpp: At global scope:
songlist.cpp:110: error: `songlist' is not a class or namespace
songlist.cpp: In function `void on_pushButton_2_clicked()':
songlist.cpp:115: error: invalid use of `this' in non-member function
database.h: At global scope:
database.h:7: warning: 'bool createConnection()' defined but not used
make: *** [songlist.o] 错误
交叉编译真是让人头大啊!从错误开始的地方找,添加头目录,发现问题还是没有解决,于是就查看songlist.h发现里面什么东西都没了,还提示任何的改动都可能造成文件内容丢失,于是就重新建立了一个工程,继续交叉编译,前面的问题都解决了 ,但是又出现了新的错误,错误如下:main.o: In function `main':
main.cpp:(.text+0x210): undefined reference to `QSqlQuery::~QSqlQuery()'
main.cpp:(.text+0x220): undefined reference to `QSqlDatabase::~QSqlDatabase()'
main.cpp:(.text+0x794): undefined reference to `QSqlDatabase::addDatabase(QString const&, QString const&)'
main.cpp:(.text+0x858): undefined reference to `QSqlDatabase::~QSqlDatabase()'
main.cpp:(.text+0xbac): undefined reference to `QSqlDatabase::setDatabaseName(QString const&)'
main.cpp:(.text+0xc48): undefined reference to `QSqlDatabase::open()'
main.cpp:(.text+0xcf0): undefined reference to `QSqlQuery::~QSqlQuery()'
main.cpp:(.text+0xd00): undefined reference to `QSqlDatabase::~QSqlDatabase()'
main.cpp:(.text+0xd68): undefined reference to `QSqlDatabase::QSqlDatabase()'
main.cpp:(.text+0xd80): undefined reference to `QSqlQuery::QSqlQuery(QString const&, QSqlDatabase)'
main.cpp:(.text+0xd90): undefined reference to `QSqlDatabase::~QSqlDatabase()'
main.cpp:(.text+0xe98): undefined reference to `QSqlQuery::exec(QString const&)'
main.cpp:(.text+0xef8): undefined reference to `QSqlDatabase::defaultConnection'
main.cpp:(.text+0xf90): undefined reference to `QSqlQuery::exec(QString const&)'
main.cpp:(.text+0x1038): undefined reference to `QSqlQuery::exec(QString const&)'
main.cpp:(.text+0x10e0): undefined reference to `QSqlQuery::exec(QString const&)'
main.cpp:(.text+0x1188): undefined reference to `QSqlQuery::exec(QString const&)'
main.cpp:(.text+0x1230): undefined reference to `QSqlQuery::exec(QString const&)'
main.o:main.cpp:(.text+0x12d8): more undefined references to `QSqlQuery::exec(QString const&)' follow
songlist.o: In function `songlist::songlist(QWidget*)':
songlist.cpp:(.text+0x1ac): undefined reference to `QSqlQuery::~QSqlQuery()'
songlist.cpp:(.text+0x47c): undefined reference to `QSqlDatabase::~QSqlDatabase()'
songlist.cpp:(.text+0x5b0): undefined reference to `QSqlDatabase::QSqlDatabase()'
songlist.cpp:(.text+0x5d8): undefined reference to `QSqlTableModel::QSqlTableModel(QObject*, QSqlDatabase)'
songlist.cpp:(.text+0x5f4): undefined reference to `QSqlDatabase::~QSqlDatabase()'
songlist.cpp:(.text+0x7c0): undefined reference to `QSqlDatabase::QSqlDatabase()'
songlist.cpp:(.text+0x7e8): undefined reference to `QSqlTableModel::QSqlTableModel(QObject*, QSqlDatabase)'
songlist.cpp:(.text+0x804): undefined reference to `QSqlDatabase::~QSqlDatabase()'
songlist.cpp:(.text+0x8cc): undefined reference to `QSqlQueryModel::query() const'
songlist.cpp:(.text+0x9d0): undefined reference to `QSqlQuery::~QSqlQuery()'
songlist.o: In function `songlist::songlist(QWidget*)':
songlist.cpp:(.text+0xbb8): undefined reference to `QSqlQuery::~QSqlQuery()'
songlist.cpp:(.text+0xe88): undefined reference to `QSqlDatabase::~QSqlDatabase()'
songlist.cpp:(.text+0xfbc): undefined reference to `QSqlDatabase::QSqlDatabase()'
songlist.cpp:(.text+0xfe4): undefined reference to `QSqlTableModel::QSqlTableModel(QObject*, QSqlDatabase)'
songlist.cpp:(.text+0x1000): undefined reference to `QSqlDatabase::~QSqlDatabase()'
songlist.cpp:(.text+0x11cc): undefined reference to `QSqlDatabase::QSqlDatabase()'
songlist.cpp:(.text+0x11f4): undefined reference to `QSqlTableModel::QSqlTableModel(QObject*, QSqlDatabase)'
songlist.cpp:(.text+0x1210): undefined reference to `QSqlDatabase::~QSqlDatabase()'
songlist.cpp:(.text+0x12d8): undefined reference to `QSqlQueryModel::query() const'
songlist.cpp:(.text+0x13dc): undefined reference to `QSqlQuery::~QSqlQuery()'
songlist.o: In function `songlist::on_pushButton_clicked()':
songlist.cpp:(.text+0x2f38): undefined reference to `QSqlTableModel::submitAll()'
songlist.o: In function `songlist::on_pushButton_4_clicked()':
songlist.cpp:(.text+0x43d0): undefined reference to `QSqlTableModel::submitAll()'
songlist.o: In function `songlist::on_pushButton_3_clicked()':
songlist.cpp:(.text+0x47b8): undefined reference to `QSqlTableModel::submitAll()'
collect2: ld returned 1 exit status
make: *** [SKTV] 错误
这样错误在交叉编译QTE时,出现了一个类似的,但是我重新解压再编译时却没有了 ,我在网上也没找到类似的问题,所以我只好再重新编译了,相同的错误还是出现,先静下心来想想,一夜没有睡好!
终于解决了,问题终于解决了。问题原因:由于交叉编译是使用qte的qmake -project手动建立的工程文件,无法自动判断是否包含数据库,所以我们如果使用了数据库既要手动在工程文件的最后添加一句话,QT +=sql这样问题就迎刃而解了,困扰了我好几天的错误,也是最关键的错误,如果无法解决,整个程序将无法编译和移植!啊,松了一口气!

目录
相关文章
|
8月前
|
Web App开发 存储 Linux
Linux(33)Rockchip RK3568 Ubuntu22.04上通过SSH运行Qt程序和关闭Chrome的密钥提示
Linux(33)Rockchip RK3568 Ubuntu22.04上通过SSH运行Qt程序和关闭Chrome的密钥提示
532 0
|
8月前
【QT】读写.ini配置文件的程序实现
【QT】读写.ini配置文件的程序实现
134 0
|
6月前
|
Linux iOS开发 开发者
Qt问题(二):无法定位程序输入点于动态链接库
动态链接库(Dynamic Link Library,简称DLL)是一种可执行文件格式,常见于Windows操作系统中,而在Linux和macOS等其他操作系统中,相似的概念通常被称为共享库(Shared Library)。动态链接库允许程序在运行时加载所需的代码和数据,而不是在编译时静态链接到应用程序中。这种方式带来了几个重要的优点:
556 3
|
4月前
|
C语言 Android开发 C++
基于MTuner软件进行qt的mingw编译程序的内存泄漏检测
本文介绍了使用MTuner软件进行Qt MinGW编译程序的内存泄漏检测的方法,提供了MTuner的下载链接和测试代码示例,并通过将Debug程序拖入MTuner来定位内存泄漏问题。
基于MTuner软件进行qt的mingw编译程序的内存泄漏检测
|
8月前
|
开发框架 自然语言处理 Linux
Qt:构建强大跨平台应用程序的框架
Qt:构建强大跨平台应用程序的框架
|
6月前
|
调度
【浅入浅出】Qt多线程机制解析:提升程序响应性与并发处理能力
在学习QT线程的时候我们首先要知道的是QT的主线程,也叫GUI线程,意如其名,也就是我们程序的最主要的一个线程,主要负责初始化界面并监听事件循环,并根据事件处理做出界面上的反馈。但是当我们只限于在一个主线程上书写逻辑时碰到了需要一直等待的事件该怎么办?它的加载必定会带着主界面的卡顿,这时候我们就要去使用多线程。
199 6
|
8月前
|
C++
QT第一个程序命名空间详解,解释ui_widget的和xxx.cpp的联系
QT第一个程序命名空间详解,解释ui_widget的和xxx.cpp的联系
137 0
|
8月前
|
人工智能 编译器 C++
新版Qt6快速打包程序脚本
不知道啥时候Qt更新了,目前是6.7.0,项目默认的生成路径改了, 从 项目目录的同级目录 改为了 项目目录中的build目录, 之前的脚本也用不了了,所以用AI更新了一下脚本, 希望能帮到大家,方便快速打包程序到桌面。
196 9
|
7月前
Qt MainWindow 程序主窗口
Qt MainWindow 程序主窗口
101 0