QT错误集合

1、no match for 'operator=='

error: no match for 'operator==' (operand types are 'ConfigINI_CPP' and 'const ConfigINI_CPP')

if (n->t() == t)

该错误提示可能是因为你在不需要的地方调用了比较操作符(比如 QList 内部需要进行查找、删除或者排序操作时)。如果你不需要比较 ConfigINI_CPP 对象的内容,考虑是否有必要进行这类操作,或者使用其他方法来处理。

重载 operator== 时避免误用:

2、std::bad_alloc

std::bad_alloc 是 C++ 标准库中的异常,通常表示 动态内存分配失败 。当 newstd::malloc 无法分配所需的内存时,就会抛出 std::bad_alloc

可能是 数组过大 ,或者有大量的动态分配,但没有及时释放。

3、Cannot queue arguments of type

QObject::connect: Cannot queue arguments of type 'QList<DiscernResult*>'

(Make sure 'QList<DiscernResult*>' is registered using qRegisterMetaType().)

个错误是由于 Qt 的信号和槽机制在默认情况下无法处理某些类型的参数(如 QList<DiscernResult*>)进行队列连接时所导致的。具体来说,当信号在不同线程之间传递时,Qt 会自动将参数放入事件队列(即使用 Qt::QueuedConnection),但是默认情况下 QList<DiscernResult*> 类型没有被注册为元类型,因此 Qt 无法正确处理它。

解决方法:

// 注册 QList<DiscernResult*> 类型

qRegisterMetaType<QList<DiscernResult*>>("QList<DiscernResult*>");

4、error: invalid use of incomplete type

error: invalid use of incomplete type 'struct PulseExtraChara_CPP'

return data()i; }

~~~~~~^

你遇到的错误 invalid use of incomplete type 'struct PulseExtraChara_CPP' 通常是由于尝试访问未完全定义的类型或结构体导致的。在 C++ 中,如果你在使用某个类型时该类型的声明不完整(即只有前向声明而没有完整定义),编译器就会无法推断该类型的具体内容,从而报出这个错误。

解决方法:

头部文件引入,或前向声明

5、error: cannot open output file debug\xxx.exe: Permission denied

:-1: error: cannot open output file debug\xxx.exe: Permission denied

6、QThread: Destroyed while thread is still running

7、QSplitter最大化问题

最大化问题,使用分割器QSplitter,添加组件deviceControl、collectControl 和 controlSpectrum,当我最大化controlSpectrum,需要执行两次才能最大化。

因为 QSplitter 会强制分配空间给其子控件(deviceControl、collectControl 和 controlSpectrum),即使你尝试最大化窗口,QSplitter 仍然会保持其布局比例。

目前的解决方案是不使用QSplitter,使用普通的水平垂直布局。没找到使用QSplitter布局的解决方案。

8、QMainWindow状态栏不见问题

状态栏不见:大小策略

ui->stackedWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Ignored); // 垂直策略改成Ignored忽略大小调整解决切换界面超过屏幕导致状态栏不见问题

9、terminate called after throwing an instance of 'std::bad_alloc'

// size 读取错误,导致超大 std::vector 分配 terminate called after throwing an instance of 'std::bad_alloc'

what(): std::bad_alloc

std::vector<double> vec(size);

size太大,多半是size读取异常导致过大

相关推荐
always_TT6 分钟前
【Python requirements.txt 依赖管理】
开发语言·python
15Moonlight15 分钟前
C++进阶(09):特殊类设计
开发语言·c++
宁风NF21 分钟前
JavaScript:网络请求与前端通信
开发语言·前端·javascript·网络·学习·ecmascript
techdashen1 小时前
Go设计取舍之三: 0.3ns每次的错误Benchmark
开发语言·后端·golang
rosmis1 小时前
agent各指标定义
android·java·开发语言
mifengxing1 小时前
Java 集合进阶(一)
java·开发语言·数据结构·复习笔记
爱码小白1 小时前
importlib模块
开发语言·前端·python
techdashen2 小时前
Go设计取舍之四: map不变时能否并发修改不同value
开发语言·后端·golang
小小小米粒2 小时前
阿姆达尔定律(Amdahl‘s Law)
java·开发语言