简体   繁体   English

我的Blackberry 10 Cascades(C ++,Qt和QML)示例应用程序在启动时崩溃,并出现以下错误

[英]My Blackberry 10 Cascades (C++, Qt & QML) sample app is crashing on startup with the following error

I am trying to make a sample Blackberry 10 Cascades app in C++, Qt, & QML in the QNX Momentics IDE, and run it in the Blackberry 10 Dev Alpha Simulator. 我正在尝试在QNX Momentics IDE中使用C ++,Qt和QML制作示例Blackberry 10 Cascades应用程序,并在Blackberry 10 Dev Alpha Simulator中运行它。 When I start running it, I get the following error messages: 当我开始运行它时,收到以下错误消息:

ApplicationPrivate::declarativeEngine: ERROR called from non-UI thread QThread(0x8067e48) ApplicationPrivate::declarativeEngine: Method called from non-UI thread ApplicationPrivate :: declarativeEngine:从非UI线程调用的错误QThread(0x8067e48)ApplicationPrivate :: declarativeEngine:从非UI线程调用的方法

I have tried googling those error messages - but I only find a few links that actually apply to my situation - and the solutions for those problems don't seem to apply to me. 我曾尝试使用Google搜索这些错误消息-但我只发现了一些实际适用于我的情况的链接-这些问题的解决方案似乎不适用于我。

I know it's got something to do with me trying to call different classes from different qml documents. 我知道尝试从不同的qml文档调用不同的类与我有关系。 (Which is something I was having trouble with before - which is why I made this sample app in the first place - to see if I could figure out how to call different classes from different qml documents). (这是我以前遇到的麻烦-这就是为什么我首先制作此示例应用程序的原因-以查看是否可以弄清楚如何从不同的qml文档中调用不同的类)。

Here is the code of my sample app. 这是我的示例应用程序的代码。 There are 7 files ( main.qml , main.cpp , app.cpp , app.hpp , Page2.cpp , Page2.h , Page2.qml ). 有7个文件( main.qmlmain.cppapp.cppapp.hppPage2.cppPage2.hPage2.qml )。 I would much appreciate if anyone could help me solve this - because I am not really sure what I am doing wrong. 如果有人可以帮助我解决这个问题,我将不胜感激-因为我不确定自己做错了什么。

Thank you. 谢谢。

(I have taken out main.cpp & reduced the code from the other 6 files to what I think are the key parts to this problem). (我已取出main.cpp并将代码从其他6个文件减少到我认为是解决此问题的关键部分)。

I know the problem has something to do with my Page2 class and the Page2.qml file. 我知道问题与我的Page2类和Page2.qml文件有关。

(I think the problem is that there is something I have to do to be able to call qt code from more than one qml files - and I just don't know what that is). (我认为问题是我必须做一些事情才能能够从多个qml文件中调用qt代码-我只是不知道那是什么)。

main.qml : main.qml


import bb.cascades 1.0

//-- create one page with a label and text
Page {
    content: Container {
        Button {
            text: "Page 2"
            onClicked: app.goToPage2
        }
    }
}

from app.cpp 来自app.cpp


App::App()
{
    qmlRegisterType<App>("GDLiteBB", 1, 0, "app");
    qmlRegisterType<Page2>("GDLiteBB", 1, 0, "Page2");

    QmlDocument *qml = QmlDocument::create("main.qml");
    qml->setContextProperty("app", this);

    AbstractPane *root = qml->createRootNode<AbstractPane>();
    Application::setScene(root);
}

void App::goToPage2() {
    Page2::getInstance();
}

from app.hpp 来自app.hpp


class App : public QObject
{
    Q_OBJECT
public:
    App();

    Q_INVOKABLE void goToPage2();
};

Page2.cpp


QmlDocument * Page2::qml_ = QmlDocument::create("Page2.qml");
AbstractPane * Page2::root_ = qml_->createRootNode<AbstractPane>();
Label * Page2::label_ = root_->findChild<Label *>("label");

Page2::Page2() : QObject() {
    ++count_;
    page2_ = this;
    qml_->setContextProperty("Page2", this);
    Application::setScene(root_);
}

Page2 *Page2::getInstance() {
    return page2_ ? page2_ : new Page2();
}

void Page2::setLabel() {
    label_->setText("This is page 2");
}

Page2.h


class Page2 : public QObject {
    Q_OBJECT

    static Page2 *page2_;
    static unsigned int count_;

    static bb::cascades::QmlDocument *qml_;
    static bb::cascades::AbstractPane *root_;
    static bb::cascades::Label *label_;

    Page2();
public:
    static Page2 *getInstance();
    virtual ~Page2();

    Q_INVOKABLE void setLabel();
};

Page2.qml


import bb.cascades 1.0
import GDLiteBB 1.0

Page {
    content: Container {
        Button {
            text: "Set Label"
            onClicked: Page2.setLabel()
        }
        Label {
            objectName: "Label"
        }
    }
}

I think your problem is these lines: 我认为您的问题是以下几行:

QmlDocument * Page2::qml_ = QmlDocument::create("Page2.qml");
AbstractPane * Page2::root_ = qml_->createRootNode<AbstractPane>();
Label * Page2::label_ = root_->findChild<Label *>("label");

These objects are being created as soon as the application code loads into memory, which means that it's happening before the event loop starts in main() . 一旦将应用程序代码加载到内存中,就会立即创建这些对象,这意味着它是在main()的事件循环开始之前发生的。 All classes that inherit from QObject need to be created after the event loop starts and destroyed before the event loop ends. 从QObject继承的所有类都需要在事件循环开始之后创建,并在事件循环结束之前销毁。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Blackberry 10 Cascades qml(C ++和QT)中的布局存在问题 - Having an issue with the layouts in Blackberry 10 Cascades, qml (C++ & QT) 尝试将QGeoSearchReply的结果添加到Blackberry 10级联(C ++,QT和QML)中的maps :: DataProvider中 - Trying to add the result of a QGeoSearchReply to a maps::DataProvider in Blackberry 10 Cascades (C++, QT & QML) 在Blackberry Cascades 10(C ++,Qt,QML)中,如何调用填充了字段的电子邮件客户端? - In Blackberry Cascades 10 (C++, Qt, QML), how do I invoke an email client with the fields populated? 如何响应在Blackberry 10 Cascades中的qml,C ++ qt列表视图中单击列表项 - How to respond to clicking on list items in a list view in qml, C++ qt, in Blackberry 10 Cascades 如何使用Cascades,Blackberry 10中的Qt / QML / C ++从另一个qml文件更改一个qml文件中的标签文本? - How do I change the label text in one qml file from another qml file using Qt/QML/C++ in Cascades, Blackberry 10? 如何在Blackberry Cascades,QML和C ++,QT的列表视图中获取Web视图 - How do I get a web view in a list view in Blackberry Cascades, QML & C++, QT 使XML数据在C ++的Blackberry 10 Cascades QML中的listItemComponents中显示 - Make XML data show in listItemComponents in Blackberry 10 Cascades QML from C++ 如何在C++、Qt、QML、Blackberry 10 Cascades Beta 3 SDK中制作图表/图形(如折线图、条形图、圆形图)等? - How to make charts/graphs (such as line graphs, bar graphs, circle graphs), etc. in C++, Qt, QML, Blackberry 10 Cascades Beta 3 SDK? 试图用Blackberry Cascades QT和QML下载图像 - Attempting to download an image in Blackberry Cascades QT, and QML 如何在Blackberry Cascades QML和QT中点击列表项组件 - How to tap on a list item component in Blackberry Cascades qml and qt
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM