Thanks to all for your comments!

I took a closer look given what Shawn wrote and looked at it through a debugger.

// main.cpp
#include <QApplication>
#include <QQmlApplicationEngine>

int main( int argc, char* argv[] )
{
    QApplication app{ argc, argv };
    QQmlApplicationEngine engine;
    const QUrl url{ u"qrc:/xxxx/main.qml"_qs };
    QObject::connect( 
        &engine, 
        &QQmlApplicationEngine::objectCreated,
        &app, 
        [url]( QObject* obj, const QUrl& objUrl ) { if (!obj && url == objUrl){ 
QCoreApplication::exit(-1); } },
        Qt::QueuedConnection
    );
    engine.load( url );
    int exitCode{ app.exec() };
    return exitCode;
}

The QTextBrowser and QTextDocument instances are instantiated in the main 
thread but the QSGRenderThread does not start running until after the call to 
app.exec(), at which time the content supplied to the QTextBrowser (and to the 
QTextDocument) is rendered. At that point, the app crashes while the layout is 
occurring on the QSGRenderThread.

As the problem is occurring in the Qt code, of course being used in a way it is 
not intended to be used in (a widget being used in a QML app), I am not going 
to pursue this approach anymore.

This will need to run on iOS, so I don’t think creating a widget app would work 
well.

Using TextEdit is a possibility as mentioned and I will look into it. It has, 
however, another larger shortcoming in that I cannot alter its QTextDocument 
from C++ (as I understand I could have with QTextBrowser), which would be of 
great use to me beyond what I have described. I’ll have to think about how to 
make it work for my purposes.

I’ll consider logging a feature request (thanks for the suggestion!) once I 
have thought this through.

Thanks again!

Sincerely,

Jeffrey Brendecke

_______________________________________________
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest

Reply via email to