Когда я раскомментирую строку ниже, я получаю утверждение:
ASSERT: "!from.isNull() && !to.isNull()" в файле [...]\qtdeclarative\src\qml\qml\qqmlpropertycache.cpp, строка 1586
#include <QGuiApplication>
#include <QtQml>
#include <QtQuick>
class Inventory : public QObject
{
Q_OBJECT
public:
Inventory() {
}
};
class InventoryModel : public QObject
{
Q_OBJECT
Q_PROPERTY(Inventory *inventory READ inventory WRITE setInventory NOTIFY inventoryChanged)
public:
InventoryModel() : mInventory(0) {
}
Inventory *inventory() const {
return mInventory;
}
void setInventory(Inventory *inventory) {
if (inventory != mInventory) {
mInventory = inventory;
emit inventoryChanged();
}
}
signals:
void inventoryChanged();
private:
Inventory *mInventory;
};
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
// qRegisterMetaType<Inventory*>();
qmlRegisterType<InventoryModel>("Qml", 1, 0, "InventoryModel");
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
return app.exec();
}
#include "main.moc"
основной.qml:
import QtQuick 2.3
import QtQuick.Controls 1.2
import Qml 1.0
ApplicationWindow {
id: window
visible: true
width: 640
height: 480
InventoryModel {
inventory: null
}
}
Я строю с Qt 5.4 (qtdeclarative находится по адресу f9ee33f9683a4cd4d1a2e41efa6e8d124e9d731d). Любые идеи, что может быть причиной этого?
inventory: window.inventoryв QML. Утверждение срабатывает, потому чтоwindow.inventoryимеет значение null. - person mcchu   schedule 06.09.2014null. - person Mitch   schedule 06.09.2014Inventory*в качестве метатипа. - person Mitch   schedule 06.09.2014