Solved QtWebEnginePage initialization seems to disable CrtDbgReport'ing
-
We use _CrtDbgReportW to help us pop up a window during asserting. However, we've recently started working with QtWebEngine, and noticed that as soon as you work with a QtWebEnginePage, it seems to disable _CrtDbgReportW.
Is there something I'm doing wrong? It seems weird to set the command line argument "--disable-breakpad" however there's not much documentation on whether it should indeed be set. Any suggestions would be a big help:
#include <QtWidgets\QMainWindow> #include <QtWidgets\QApplication> #include <QtWebEngineWidgets\QtWebEngineWidgets> #include <QtWidgets\QMenuBar> // custom assert mechanism bool MyAssert( const char* const pSzExpr, //expression const char* szFile, const unsigned nLine, const char* szFunc ) { size_t len = 0; std::wstring wsFile(strlen(szFile)+1, L'#'); mbstowcs_s(&len, &wsFile[0], wcslen(wsFile.c_str()), szFile, strlen(szFile) + 1); std::wstring wsMsg(strlen(pSzExpr)+1, L'#'); mbstowcs_s(&len, &wsMsg[0], wcslen(wsMsg.c_str()), pSzExpr, strlen(pSzExpr) + 1); return _CrtDbgReportW(_CRT_ASSERT, wsFile.c_str(), nLine, nullptr, wsMsg.c_str()) != 1; } #define ASSERT( EXPR ) (( !!(EXPR) || MyAssert((#EXPR),__FILE__,__LINE__,__FUNCTION__) ) || (_CrtDbgBreak(), 0) ) // qtwebengine's chromium disables ASSERTing via _CrtDbgReportW inside process_startup_helper.cc::SetupCRT // by setting _CrtSetReportMode(_CRT_ASSERT, 0) when !command_line.HasSwitch(switches::kDisableBreakpad) // ie. command line argument "--disable-breakpad" needs to be _set_ int main( int argc, char *argv[] ) { QApplication app( argc, argv ); QMainWindow* mainWin = new QMainWindow(); QWebEngineView* pView = new QWebEngineView(mainWin); ASSERT(false && "Pre-WebEnginePage"); // asserts here (and anytime before)... auto pPage = pView->page(); ASSERT(false && "Post-WebEnginePage"); // ... but does not assert here (or hereafter) pPage->setUrl( QUrl("http://www.google.com") ); // setup rest of the application and basic menu controls QMenu* pQFile = mainWin->menuBar()->addMenu( QIcon(), "&File" ); mainWin->addAction( pQFile->addAction( QIcon(), "&Quit", qApp, SLOT( quit() ), Qt::Key_Q ) ); mainWin->setCentralWidget( pView ); mainWin->resize( 1024, 750 ); mainWin->show(); auto result = app.exec(); // tidy up and quit delete pView; delete mainWin; ASSERT(false && "Done"); // does not assert here either return result; }
-
Rather than re-directing to CrtDbgReport, I can simplify the problem even further, and fail to assert post-initialization by using the pre-existing "_ASSERT" macro:
QWebEngineView* pView = new QWebEngineView(mainWin); _ASSERT(false && "Pre-WebEnginePage"); // asserts here (and anytime before)... auto pPage = pView->page(); _ASSERT(false && L"Post-WebEnginePage"); // ... but does not assert here (or hereafter) pPage->setUrl(QUrl("http://www.google.com"));
Any comments would be appreciated. I have also filed a bug: https://bugreports.qt.io/browse/QTBUG-57634
-
Fun update for anyone interested, searching for "breakpad chromium" is much more informative than "disable-breakpad chromium." Apparently "breakpad" is a crash reporting tool used by chromium, which suppresses CRT's ASSERTs when it is active (which is by default).
Pass in "--disable-breakpad" as a commandline argument in the main method (it is detected by the win32 ::GetCommandLineW call), or consider saving the crt report mode before the web engine page initializes, and then restore it immediately afterwards.