[Qt-creator] crash in QReadLocker when I try to reuse QmlDesigner source code

Hartmann Thomas Thomas.Hartmann at theqtcompany.com
Mon Oct 12 12:22:13 CEST 2015


Hi,


this is code from our tests that does more or less what you need:


static Model* createModel(const QString &typeName, int major = 1, int minor = 1, Model *metaInfoPropxyModel = 0)
{
    Model *model = Model::create(typeName, major, minor, metaInfoPropxyModel);

    QPlainTextEdit *textEdit = new QPlainTextEdit;

    textEdit->setPlainText(QString("import %1 %3.%4; %2{}").arg(typeName.split(".").first())
            .arg(typeName.split(".").last())
            .arg(major)
            .arg(minor));

    NotIndentingTextEditModifier *modifier = new NotIndentingTextEditModifier(textEdit);
    modifier->setParent(textEdit);

    RewriterView *rewriterView = new RewriterView(RewriterView::Validate, model);
    rewriterView->setCheckSemanticErrors(false);
    rewriterView->setTextModifier(modifier);

    model->attachView(rewriterView);

    return model;
}

In your code I am confused by  "m_rewriterView->setPlainText(in.readAll());". This method does not exist in our code base.

The reason you need the QPlainTextEdit is that the "rewriting" of QML is implemented on top of the text edit.

The model of the QmlDesigner is not multi threaded, but the code model for qml that we share with the qml editor is.


I would suggest to look at the auto tests in qtcreator\tests\auto\qml\qmldesigner\coretests to check how the model of

the QmlDesigner is working.


If you are just reading simple json style QML (no writing of QML) then using QmlJS::SimpleReader might be an alternative.


Kind Regards,

Thomas Hartmann


________________________________
From: qt-creator-bounces+thomas.hartmann=theqtcompany.com at qt-project.org <qt-creator-bounces+thomas.hartmann=theqtcompany.com at qt-project.org> on behalf of Дмитрий Шмыков <d.shmykov at nexters.com>
Sent: Monday, October 12, 2015 11:52 AM
To: qt-creator at qt-project.org
Subject: [Qt-creator] crash in QReadLocker when I try to reuse QmlDesigner source code

Hi friends.

I've tried to write a question to the IRC but its text seems to be long so I ask here if anybody can help me with reusing QTC source code in my project. This question isn't bound directly with any QTC bug.

I'm writing a function that takes qml file path as input and should return populated QmlDesigner::Model as output. Then I use QmlDesigner::Model to work with qml document that contains domain specific info for my application.

I'm gettng a crash in QReadLocker and I've posted the question to this forum https://forum.qt.io/topic/59648/crash-in-qreadlocker .
[https://secure.gravatar.com/avatar/9f9b9b584229f29810f76f3550cfe513?size=128&default=mm&rating=pg]<https://forum.qt.io/topic/59648/crash-in-qreadlocker>

crash in QReadLocker
I've experienced the crash in QReadLocker(QReadWriteLock*) constructor. It calls QReadLocker::relock() member function with a strange intristic functionality that modifies pointer q_val. Inside QReadLocker::relock() the QReadLocker::readWriteLock() is cal...
Read more...<https://forum.qt.io/topic/59648/crash-in-qreadlocker>




Here's the function's source code. Please tell me if I reuse QTC source code incorrectly.

std::shared_ptr<QmlDesigner::Model> DialogFactory::populateNodeTreeFromFile(const std::string& fileName)
{
    // reading the file
    const QString qfileName = QString::fromStdString(fileName);
    QFile f(qfileName);
    if (!f.open(QFile::ReadOnly | QFile::Text))
        return nullptr;
    QTextStream in(&f);
    m_rewriterView->setPlainText(in.readAll()); // m_rewriterView is created in the constructor
    // populating the model
    m_docModel->setFileUrl(QUrl::fromLocalFile(qfileName));
    m_docModel->setRewriterView(m_rewriterView);
    //--
    return m_docModel;
}

Thanks in advance.
--
[X]     Шмыков Дмитрий
программист
www.nexters.com<http://www.nexters.com>
+7 985 915 0966
skype: dmitryshm1

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/qt-creator/attachments/20151012/cc628acb/attachment.html>


More information about the Qt-creator mailing list