Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
277 views
in Technique[技术] by (71.8m points)

qml - Unable to assign QString to QQuickItem* with Qt.resolvedUrl

I have the following code:

Tabs {
    Tab {
        id: financialDetailsTab
        title: i18n.tr("Financial Details")
        page: Qt.resolvedUrl("FinancialDetails.qml")
    }
    Tab {
        id: monthlyBudgetTab
        title: i18n.tr("Monthly Budget")
        page: Qt.resolvedUrl("MonthlyBudget.qml")
    }
    Tab {
        id: annualBudgetTab
        title: i18n.tr("Annual Budget")
        page: Qt.resolvedUrl("AnnualBudget.qml")
    }
    Tab {
        id: savingsGoalsTab
        title: i18n.tr("Savings Goals")
        page: Qt.resolvedUrl("SavingsGoals.qml")
    }
}

which is generating the following errors:

Unable to assign QString to QQuickItem*
Unable to assign QString to QQuickItem*
Unable to assign QString to QQuickItem*
Unable to assign QString to QQuickItem*

on the lines where Qt::resolvedUrl is being used. The Tabs component is a part of the Ubuntu SDK, and not Qt Quick, and the only example of it's use doesn't provide much insight into the problem.

I've added the exact same lines as properties of the MainView, outside of the Tabs component, and the problem has not been evident there, leading me to believe the issue lies with the Ubuntu component. While the problem may be with the Ubuntu component, some help in understanding what the error message actually means would be helpful.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The error you are getting means that the 'page' property from Tab { } item can't accept a string (or url) content, it wants an Item or derived component.

So I'm pretty sure your AnnualBudget or SavingsGoals files can be instanciated as components, since they are in the same folder (so no import needed) and the file name first letter is uppercase so QML engine automatically allows you to do this :

Tabs {
    Tab {
        id: financialDetailsTab
        title: i18n.tr("Financial Details")
        page: financePage;
    }
}

FinancialDetails {
    id: financePage;
}

So 'financePage' is an ID, so for the QML engine it's a QQuickItem pointer and it will accept it. Just do the same for each tab/page pair.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...