我正在为symbian平台开发Qt移动应用程序。我有一个改变当前显示屏幕的功能,这个功能是一个插槽,因此可以从C ++端和QML调用。
public slots:
void ChangeView(const QString & viewPath);
void Controller::ChangeView(const QString & viewPath) {
if(this->view->status() == QDeclarativeView::Ready) {
QDeclarativeProperty * property = new QDeclarativeProperty(this->view,"source", this->context);
if(property->isValid()) {
property->write(QVariant(viewPath));
property->~QDeclarativeProperty();
}
}
else if(this->view->status() == QDeclarativeView::Error) {
QList<QDeclarativeError> errors = this->view->errors();
for(int i = 0; i < errors.size(); ++i) {
qDebug() << "Error: " << errors.at(i);
}
errors.~QList();
}
}
从C ++调用此函数可以正常工作,
void Controller::Show() {
this->window->setCentralWidget(this->view);
this->menu->MainMenu();
this->ChangeView("qml/Streemio/Login.qml");
this->window->show();
}
然而,当我从QML调用它时,它会崩溃应用程序。
Button {
id: channels
anchors.top: nowPlaying.bottom
anchors.topMargin: -1
label: "Channels"
subLabel: "listen to default playlists"
imgSource: "qrc:Streemio/img/channel_menu.png"
fontSize: 14
subFontSize: 7
buttonWidth: container.width
Keys.onSelectPressed: {controller.ChangeView("qml/Streemio/Channels.qml")}
Keys.onDownPressed: {search.focus = true; flickArea.contentY = 75}
Keys.onUpPressed: {nowPlaying.focus = true; flickArea.contentY = 0}
}
这是应用程序输出。
Starting application...
Application running with pid 770.
CAknSignalDataObserver::HandleUpdateL: UMA
CAknSignalPane::ShowUmaIconL: begin
CAknSignalPane::LoadSignalIconL: uma-off
CAknSignalPane::ShowUmaIconL: end
[Qt Message] QNetworkReplyImpl::_q_startOperation was called more than once
Process 770, thread 771 stopped at 0x71547a2a: A data abort exception has occurred.
Finished.
我在这里做错了什么?谢谢。
答案 0 :(得分:1)
您是否正在更改处理按钮按下的视图?如果是这样,那么按钮在其按下处理程序时就会被破坏并且崩溃。解决方案是让changeView()方法使更改异步发生。实现这一目标的最简单方法是将实际视图更改代码放入changeView()使用Qt :: QueuedConnection调用的插槽中。这将导致当前视图被安全销毁,并在下次输入事件循环时创建新视图。
答案 1 :(得分:0)
我会在这里猜测一下,并说有问题的代码是这一行:
property->~QDeclarativeProperty();
除非你在幕后做一些非常怪异的事情,否则这行应该可以阅读
delete property;