Solved Exception when start an "empty" Qt Widgets application
-
@mchinand, thank you for your reply.
I did not add any my own code, the codes are from project wizard, an "empty" Qt Widgets Application generate by QtCreator.
The stack trace shows the problem is in Qt's font engine and Windows DirectWrite API, maybe the exception related to some kind of my system's font problem.codes :
pro:#------------------------------------------------- # # Project created by QtCreator 2017-09-07T14:36:24 # #------------------------------------------------- QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = aaa TEMPLATE = app SOURCES += main.cpp\ mainwindow.cpp HEADERS += mainwindow.h FORMS += mainwindow.ui
main.cpp:
#include "mainwindow.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); }
mainwindow.ui:
<ui version="4.0"> <class>MainWindow</class> <widget class="QMainWindow" name="MainWindow" > <property name="geometry" > <rect> <x>0</x> <y>0</y> <width>400</width> <height>300</height> </rect> </property> <property name="windowTitle" > <string>MainWindow</string> </property> <widget class="QMenuBar" name="menuBar" /> <widget class="QToolBar" name="mainToolBar" /> <widget class="QWidget" name="centralWidget" /> <widget class="QStatusBar" name="statusBar" /> </widget> <layoutDefault spacing="6" margin="11" /> <pixmapfunction></pixmapfunction> <resources/> <connections/> </ui>
mainwindow.h:
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); private: Ui::MainWindow *ui; }; #endif // MAINWINDOW_H
mainwindow.cpp:
#include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); } MainWindow::~MainWindow() { delete ui; }
-
@mchinand
BTW, I checked my QtCreator's UI designer, the font shows like this:Is this "04b_21" strange? The "SimSun" font is because my Windows default language is Simplified Chinese.
And also, I checked my dwrite.dll version is: 6.1.7601.23688.
-
@xuguangxiao said in Exception when start an "empty" Qt Widgets application:
It seems to be crashing with QFontDatabase::findFont on the stack so try another font and see how it goes... I don't think it should crash anyway, though.
-
@BjornW thank you for your reply.
I've tried "Courier New" font and "Arial" font, same result.
-
I just tried making an MSVS2015 project to call DWriteCreateFactory with IDWriteFactory UUID directly, there was no exception thrown. But when I changed to call DWriteCreateFactory with UUID IDWriteFactory2, the exception appeared, and DWriteCreateFactory API returned fail. And then, I checked QtBase source codes, in the createDirectWriteFactory function in file qwindowsfontdatabase.cpp, Qt will try to call DWriteCreateFactory with IDWriteFactory2 UUID, if failed, call the API with IDWriteFactory UUID:
static void createDirectWriteFactory(IDWriteFactory **factory) { *factory = Q_NULLPTR; static const DWriteCreateFactoryType dWriteCreateFactory = resolveDWriteCreateFactory(); if (!dWriteCreateFactory) return; IUnknown *result = NULL; #if defined(QT_USE_DIRECTWRITE2) dWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory2), &result); #endif if (result == NULL) { if (FAILED(dWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), &result))) { qErrnoWarning("DWriteCreateFactory failed"); return; } } *factory = static_cast<IDWriteFactory *>(result); }
My Qt was not local built from source. I just downloaded the install package. Maybe the build environments are different. This is the reason of the problem. Maybe Qt needs to improve the compiling test scripts or let some other changing for this situation.
-
@xuguangxiao Hi, I tried to also get an exception, using MSVS2015, but alas I couldn't get it, could you try this simple program:
#include <iostream> #include "dwrite.h" #include "dwrite_2.h" #pragma comment(lib,"dwrite.lib") void main() { IUnknown* result = NULL; DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED,__uuidof(IDWriteFactory2),&result); std::cout << result; }
I saved this as test.cpp, opened a Developer Command Prompt for VS2015 and typed:
cl/EHa test.cpp
Then I got a test.exe file, when I tested on Win7SP1 it prints 00000000, in Windows 8 and Windows 10 it prints a number > 0. But no C++ exceptions :-(
P.S. The DWriteCreateFactory call returns E_NOINTERFACE (0x8004002) in Windows 7, and OK in Windows 8 and 10.
-
@hskoglund Hi, I've just tried your code. Yes, there was no exception print in the console, same as you.
But the QtCreator debug the program in a windows debugger, if you start the program by cdb, you can see the exception print, like this:E:\Documents\aaa>C:\WinDDK\7600.16385.0\Debuggers\cdb.exe test.exe Microsoft (R) Windows Debugger Version 6.11.0001.404 AMD64 Copyright (c) Microsoft Corporation. All rights reserved. CommandLine: test.exe Symbol search path is: *** Invalid *** **************************************************************************** * Symbol loading may be unreliable without a symbol search path. * * Use .symfix to have the debugger choose a symbol path. * * After setting your symbol path, use .reload to refresh symbol locations. * **************************************************************************** Executable search path is: ModLoad: 00000001`3f180000 00000001`3f1c9000 image00000001`3f180000 ModLoad: 00000000`771c0000 00000000`7736a000 ntdll.dll ModLoad: 00000000`770a0000 00000000`771bf000 C:\Windows\system32\kernel32.dll ModLoad: 000007fe`fd270000 000007fe`fd2da000 C:\Windows\system32\KERNELBASE.dl l ModLoad: 000007fe`ee7d0000 000007fe`ee94f000 C:\Windows\system32\DWrite.dll ModLoad: 000007fe`ff430000 000007fe`ff4cf000 C:\Windows\system32\msvcrt.dll ModLoad: 000007fe`fd360000 000007fe`fd43b000 C:\Windows\system32\ADVAPI32.dll ModLoad: 000007fe`fd340000 000007fe`fd35f000 C:\Windows\SYSTEM32\sechost.dll ModLoad: 000007fe`fdb90000 000007fe`fdcbd000 C:\Windows\system32\RPCRT4.dll ModLoad: 000007fe`ff280000 000007fe`ff2e7000 C:\Windows\system32\GDI32.dll ModLoad: 00000000`76fa0000 00000000`7709a000 C:\Windows\system32\USER32.dll ModLoad: 000007fe`ff000000 000007fe`ff00e000 C:\Windows\system32\LPK.dll ModLoad: 000007fe`fdf60000 000007fe`fe02a000 C:\Windows\system32\USP10.dll (af0.8d4): Break instruction exception - code 80000003 (first chance) *** ERROR: Symbol file could not be found. Defaulted to export symbols for ntdl l.dll - ntdll!CsrSetPriorityClass+0x40: 00000000`77267800 cc int 3 0:000> g ModLoad: 000007fe`fe030000 000007fe`fe05e000 C:\Windows\system32\IMM32.DLL ModLoad: 000007fe`fe060000 000007fe`fe169000 C:\Windows\system32\MSCTF.dll ModLoad: 000007fe`fae70000 000007fe`fae73000 C:\Windows\system32\api-ms-win-co re-synch-l1-2-0.DLL (af0.8d4): C++ EH exception - code e06d7363 (first chance) (af0.8d4): C++ EH exception - code e06d7363 (first chance) 000000000000000000000000`00030552 c3 ret 0:000> q quit: E:\Documents\aaa>
Thank you for your attention!
-
@xuguangxiao I also just tried same procedure with cdb.exe but still no exceptions for me :-(
C:\Program Files (x86)\Windows Kits\8.1\Debuggers\x64>cdb test.exe Microsoft (R) Windows Debugger Version 6.3.9600.17336 AMD64 Copyright (c) Microsoft Corporation. All rights reserved. CommandLine: test.exe Symbol search path is: *** Invalid *** **************************************************************************** * Symbol loading may be unreliable without a symbol search path. * * Use .symfix to have the debugger choose a symbol path. * * After setting your symbol path, use .reload to refresh symbol locations. * **************************************************************************** Executable search path is: ModLoad: 00000001`3f670000 00000001`3f6b6000 image00000001`3f670000 ModLoad: 00000000`76dd0000 00000000`76f7a000 ntdll.dll ModLoad: 00000000`76cb0000 00000000`76dcf000 C:\Windows\system32\kernel32.dll ModLoad: 000007fe`fcb30000 000007fe`fcb9a000 C:\Windows\system32\KERNELBASE.dl l ModLoad: 000007fe`ef510000 000007fe`ef6a7000 C:\Windows\system32\DWrite.dll ModLoad: 000007fe`fd5b0000 000007fe`fd64f000 C:\Windows\system32\msvcrt.dll ModLoad: 000007fe`fd4d0000 000007fe`fd5ab000 C:\Windows\system32\ADVAPI32.dll ModLoad: 000007fe`fd490000 000007fe`fd4af000 C:\Windows\SYSTEM32\sechost.dll ModLoad: 000007fe`fefb0000 000007fe`ff0dd000 C:\Windows\system32\RPCRT4.dll ModLoad: 000007fe`feb40000 000007fe`feba7000 C:\Windows\system32\GDI32.dll ModLoad: 00000000`76bb0000 00000000`76caa000 C:\Windows\system32\USER32.dll ModLoad: 000007fe`fe950000 000007fe`fe95e000 C:\Windows\system32\LPK.dll ModLoad: 000007fe`fd3c0000 000007fe`fd48a000 C:\Windows\system32\USP10.dll (d50.d24): Break instruction exception - code 80000003 (first chance) *** ERROR: Symbol file could not be found. Defaulted to export symbols for ntdl l.dll - ntdll!CsrSetPriorityClass+0x40: 00000000`76e77980 cc int 3 0:000> g ModLoad: 000007fe`febb0000 000007fe`febde000 C:\Windows\system32\IMM32.DLL ModLoad: 000007fe`fd2b0000 000007fe`fd3b9000 C:\Windows\system32\MSCTF.dll ModLoad: 000007fe`f6af0000 000007fe`f6af3000 C:\Windows\system32\api-ms-win-co re-synch-l1-2-0.DLL 0000000000000000ntdll!ZwTerminateProcess+0xa: 00000000`76e1bffa c3 ret 0:000> q quit: C:\Program Files (x86)\Windows Kits\8.1\Debuggers\x64>
It looks pretty similar, except those 2 C++ EH exception lines and that address 0x30552, a low value like that suggests an injected DLL, but probably not Defender, perhaps you are running some other Antivirus program?
-
@hskoglund, maybe the problem was caused by the windows system. I think I should ask somebody of Microsoft :-).
Thank you again! -
@xuguangxiao Hi, I also have this problem. I found on MSDN that minimum supported client for IDWriteFactory2 is Windows 8.1. Probably because of that, we have this exception.