Qt开发奇葩问题总集

7 篇文章 0 订阅

Qt开发奇葩问题总集【持续更新中】

说明:

  • 说明 主要记录一些 Qt 开发以及QtCreator 使用过程中遇到的奇葩问题 记录
  • 有些已经解决(有些也晓不得为啥就能解决)有些还未解决
  • 其实觉得问题奇葩 就是目前个人的知识水平还不够 晓不得为啥这样能解决 希望有路过的大佬懂的原因的能解下惑
  • ✔️ : 解决 ❌ :未解决 ⚪️ :未知

使用 QColorDialog 控制台出现提示 ❌

使用 QColorDialog 控制台出现提示 也不是报错叭 但是看到总不舒服 202106171602 未解决

setGeometry: Unable to set geometry 400x400+2619+336 (frame: 416x439+2611+305) on QWidgetWindow/"QColorDialogClassWindow" on "\\.\DISPLAY2". Resulting geometry: 522x393+2619+336 (frame: 538x432+2611+305) margins: 8, 31, 8, 8 minimum size: 522x393 maximum size: 522x393 MINMAXINFO maxSize=0,0 maxpos=0,0 mintrack=538,432 maxtrack=538,432)

Qt 运行程序控制台 自动输出 CUserInputProcessor::OnSetFocus in 之类的 ⚪️

环境: win7 Qt Creator4.13.1 Qt5.12.10
现象描述:
QtCreator 运行程序 控制台自动弹出 换个项目依然是 但是不影响程序执行 就是有点看着不舒服 就是不爽。

CUserInputProcessor::OnSetFocus in
CUserInputProcessor::OnSetFocus out

百度网友解决办法是卸载百度输入法 运行的电脑上确实有百度输入法 同时 发现运行程序时鼠标点Mainwindow外面 输出out 里面输出in

换用讯飞输入法后控制台出现:

iFlyIMEEntry ::DllMain | strPath:D:\Program Files (x86)\iFlytek\iFlyIME\3.0.1727
iFlyIMEEntry::ImeInquire | pos1
::GetiflyimeModule | strBuf:D:\Program Files (x86)\iFlytek\iFlyIME\3.0.1727
::GetiflyimeModule | hModule:0X2edd0000iFlyIMEEntry::ImeInquire | pos2
iFlyIMEEntry::ImeSelect | pos1iFlyIMEEntry::ImeSelect | pos2iFlyIMEEntry::ImeSelect | pos1iFlyIMEEntry::ImeSelect | pos2

解决办法: 卸载百度输入法

出现原因: 希望路过的大佬能为我解解惑

Qt 打开软件出现 缺库 api-ms-win-core-sysinfo-l1-2-o.dll ✔️

环境:QtCreater4.13.1 Qt5.12.10

系统:Win7

出现问题: 忘记截图了 虽然不影响使用 但看起来不舒服

解决办法:

1、下载 api-ms-win-core-sysinfo-l1-2-o.dll

2、将dll 放到 C:\Windows\System32 目录下 如果出现了两次提示没有api-ms-win-core-sysinfo-l1-2-o.dll 分别把 32(C:\Windows\System32 )和64位(C:\Windows\SysWOW64)的dll放到目录下

说明:不知道是dll的原因还是啥 C:\Windows\System32 目录下放 32位的提示错误 最后是交换放置

Qt 使用多线程连接信号槽 发生错误 ✔️

环境:QtCreater4.13.1 Qt5.12.10

系统:Win7

QObject::connect: Cannot queue arguments of type 'QList<PsdData>'
(Make sure 'QList<PsdData>' is registered using qRegisterMetaType()

解决办法:

connect 之前调用 qRegisterMetaType()注册数据类型 (自定义的数据类型PsdData)

#include <QMetaType>
qRegisterMetaType<QList<PsdData>>("QList<PsdData>");
qRegisterMetaType<QList<rgbPoint>>("QList<rgbPoint>");

Qt 多线程 ❌

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
CSProxy refcount 22
==========> ExitInstance :gLayerInfo delete 873638104<==============Unload CSProxy from E:\Works_Project\DMCA\DMCA_PSD\Software\build-DMCA_PSD-Desktop_Qt_5_12_10_MinGW_32_bit\debug\DMCA_PSD.exe...
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc

Qt 使用MSVC 编译器 显示中文字符 报错 ✔️

 error: C2001: newline in constant
 .......
 error: C3872: '0xe11b': this character is not allowed in an identifier
 

解决办法:将当前文档转化为 UTF-8 使用QStringLiteral()包裹字符串

保存UTF-8: (都需要用QStringLiteral包裹中文字符)

1、使用记事本另存为 选择UTF-8

2、Qt Creator 工具->选项->文本编辑器->Behavior->文件编码 默认编码格式->UTF-8 UTF-8 BOM->如果编码是UTF-8则添加

error: LNK2019 ✔️

device_sapp.obj:-1: error: LNK2019: unresolved external symbol "public: virtual __cdecl device_sapp::~device_sapp(void)" (??1device_sapp@@UEAA@XZ) referenced in function "public: virtual void * __cdecl device_sapp::`scalar deleting destructor'(unsigned int)" (??_Gdevice_sapp@@UEAAPEAXI@Z)

虚基类的构造函数与析构函数 与继承的类的析构函数重复

Exception at 0x7fefdadb87d, code: 0xe06d7363: C++ exception, flags=0x1 (execution cannot be continued) (first chance) in dwrite!DWriteCreateFactory
Exception at 0x7fefdadb87d, code: 0xe06d7363: C++ exception, flags=0x1 (execution cannot be continued) (first chance) in dwrite!DWriteCreateFactory
error: LNK2019
qcustomplot.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl QPrinter::QPrinter(enum QPrinter::PrinterMode)" (__imp_??0QPrinter@@QEAA@W4PrinterMode@0@@Z) referenced in function "public: bool __cdecl QCustomPlot::savePdf(class QString const &,int,int,enum QCP::ExportPen,class QString const &,class QString const &)" (?savePdf@QCustomPlot@@QEAA_NAEBVQString@@HHW4ExportPen@QCP@@00@Z)

出现这样的错误一般是声明了函数没有实现其定义,比如这里提示的是没有自定义类MyWidget的实现函数。如果你已经检查了确定定义是有的,比如我这个就确实有定义了的,那就把该项目编译出的build debug文件夹给删除掉,再重新编译,注意是编译出来的整个文件夹一起删,而不是clean清除后重新构建。

忘记添加: printsupport

error: LNK2038 ✔️

SmartFFT.lib(smartfft.obj):-1: error: LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj

原因:用release链接到一个debug编译的lib或者debug模式链接到一个release编译的lib

error: C2131 ✔️

error: C2131: expression did not evaluate to a constant

原因:MSVC编译器 使用变量定义数组的尺寸

error: LNK2005 ✔️

error: LNK2005: "void __cdecl doFFT(short *,int,double *)" (?doFFT@@YAXPEAFHPEAN@Z) already defined in main.obj

原因:需要使用static定义 函数为静态方法

Cannot send events to objects owned by a different thread ✔️

环境:QtCreater4.13.1 Qt5.12.10

系统:Win7

问题描述:Qt 使用std::thread调用了主线程的对象

ASSERT failure in QCoreApplication::sendEvent: "Cannot send events to objects owned by a different thread. Current thread 0x0xdbd5b20. Receiver 'MainWindow' (of type 'MainWindow') was created in thread 0x0x364090", file kernel\qcoreapplication.cpp, line 578
(Press Retry to debug the application)

解决办法:使用Qt的的信号槽机制跨线程通信

Cannot open include file: ‘corecrt.h’ ✔️

环境:QtCreater4.13.1 Qt5.12.10

系统:Win7

原因是更改系统之前安装的Windows SDK版本

Cannot open include file: ‘corecrt.h’
D:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\crtdefs.h:10: error: C1083: Cannot open include file: 'corecrt.h': No such file or directory
Cannot open include file: ‘Windows.h’
E:\Works_Project\Spectrum_Analyzer\PCIE\SPEED_APP_win\APP_win\PcieSpeed\pcie_fun.c:4: error: C1083: Cannot open include file: 'Windows.h': No such file or directory

1、尝试修改系统环境变量 未解决

2、通过baidu 在Pro里面链接 库 能解决第一个问题 但会出现第二个问题更严重 (治标不治本) 未解决

INCLUDEPATH += "C:/Program Files (x86)/Windows Kits/10/Include/10.0.10240.0/ucrt"
LIBS += -L"C:/Program Files (x86)/Windows Kits/10/Lib/10.0.10240.0/ucrt/x64"

(我的个人想法出现问题的大概率需要在哪里重新配置一下就好)

3、没有找到再哪里找到可以配置的地方 于是重新装了Qt 依然 未解决

4、但是再次打开Qt发现里面的配置配色跟卸载前一样 想到Qt会把配置文件放到用户目录下 解决

C:\Users\用户\AppData\Roaming\QtProject

先备份一下文档 并删除 再次打开QtCreator 这时候打开花的时间有点长 它重新从系统获取了配置 这时候重新测试没有报错

说明: 遇到这种问题可以不用卸载Qt 直接删除 这个文件就行 但之前辛苦配置出自己的工作环境就搞掉 需要对QtProject每个文件设置什么东西了解下 出现问题删除对应文件即可

Heap block modified past requested size ✔️

  • 在Debug 模式出现 Release模式未出现
  • 在使用 new 指针 程序会莫名崩溃 调试时程序会在退出函数时报错
HEAP[xxx.exe]: Heap block at 000000000A611EB0 modified at 000000000A619EF4 past requested size of 8034
Debug Error!
Program: ...est-Desktop_Qt_5_12_10_MSVC2015_64bit\debug\xxx.exe
HEAP CORRUPTION DETECTED: after Normal block (#240865) at 0x000000000363AC90.
CRT detected that the application wrote to memory after end of heap buffer.
(Press Retry to debug the application)
  • 最后通过排查打印发现 for循环的终止条件是 <=N 同时循环指针超出范围: x[-1] 将循环终止条件改为<N
  • 出现此类问题一般都是使用指针超出向系统申请的内存如: int *x=new int[5]; x[5];x[-1];

参考:Heap block modified past requested size

error: C4430 ✔️

  • 网上说是因为 头文件相互包含
  • 程序之前是能用的没问题
  • 从 giee 下载下来 文件格式是Unix(LF) 把它换成 Windos(CRLF)就可以了
  • 后面确认可能因为忘记加dll
error: C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int

error: undefined reference to `WinMain@16’ ⚪️

  • 重新构建程序

QSettings: failed to set subkey “xxx”: 拒绝访问 ✔️

QSettings: failed to set subkey "SystemTray": 拒绝访问
  • 非管理员运行程序修改注册表
  • 右键管理员运行程序

FTH: (9144) ✔️

FTH: (9144): *** Fault tolerant heap shim applied to current process. This is usually due to previous crashes. ***
FTH: (9356): *** Fault tolerant heap shim applied to current process. This is usually due to previous crashes. ***
Exception at 0x7fefce6b87d, code: 0xe06d7363: C++ exception, flags=0x1 (execution cannot be continued) (first chance) in dwrite!DWriteCreateFactory
Exception at 0x7fefce6b87d, code: 0xe06d7363: C++ exception, flags=0x1 (execution cannot be continued) (first chance) in dwrite!DWriteCreateFactory
  • 由于之前的程序发生内存泄露 到注册表以下路径删除 你的程序

  • HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers

  • 方法2 未测试

开注册表,设置HKLM\Software\Microsoft\FTH\Enabled 为0
打开CMD,运行Rundll32.exe fthsvc.dll,FthSysprepSpecialize

error: LNK1104 ✔️

error: LNK1104: 无法打开文件“xxx.lib”
  • 排除路径错误
  • 依赖库缺失
  • 编译版本不一致

error: LNK2001 ✔️

error: LNK2001: 无法解析的外部符号 "private: static class QFile MainWindow::out" (?out@MainWindow@@0VQFile@@A)
  • 静态变量声明 到类的外面
singlecentral.obj:-1: error: LNK2001: 无法解析的外部符号 "public: virtual void __cdecl SingleCentral::GetViewImage(class QImage &)" (?GetViewImage@SingleCentral@@UEAAXAEAVQImage@@@Z)
  • 虚函数仅声明没定义

表达式必须是可修改的左值 ✔️

结构体中对字符数组赋值 表达式必须是可修改的左值
  • 使用strcpy 复制字符串
  • 将字符数组改为字符指针
  • 使用string 代替

QtCreator 计算机中丢失python36.dll ✔️

  • 出现原因可能是 之前安转python3.6 后面换成了3.7 系统环境变量里面只有3.7

  • 不影响正常使用 看着不舒服

在这里插入图片描述

  • 下载Python36.dll

    • 3.6的版本具有编译好的只有3.6.8

    • 下载一个编译好的压缩包

    • 找到 Python36.dll 放到 C:\Windows\System32 路径下

    • 应该单独安装Python3.6 并添加环境变量应该也是可行的(有多个版本的 尽量把3.6放在其他版本前)

      • 至于笔者为啥不安装 一是已经有3.7的环境 改了环境变量后默认就是3.6了 二是麻烦这样

      在这里插入图片描述

VS 动态链接库无 .lib ✔️

  • VS 生成动态链接库 xxx.dll xxx.lib(如果有导出函数,没有则不生成)
  • 这里的xxx.lib 虽然后缀名和 静态库相同 但意义完全不同 它是动态库的导入库只包含导出定义
  • DLL项目中必须至少导出一个函数、变量或者类才会有.lib生成, 没有导出的话就不生成.lib文件
  • 参考

CSProxy refcount 37 ❌

CSProxy refcount 37
Loading E:\WorkSpace\QtPractice\AudioDevice\build-AudioDevice-Desktop_Qt_5_12_10_MinGW_32_bit\debug\AudioDevice.exe...
WSPStartup ===> E:\WorkSpace\QtPractice\AudioDevice\build-AudioDevice-Desktop_Qt_5_12_10_MinGW_32_bit\debug\AudioDevice.exe
使用链式SPI
  • 23
    点赞
  • 45
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值