मैं नीचे दिए गए कोड के साथ टैब घटक में एक नया टैब जोड़ने का प्रयास कर रहा हूं।
दौड़ते समय कोई त्रुटि रिपोर्ट नहीं की गई है लेकिन कोई अतिरिक्त टैब नहीं दिखाया गया है। मैंने टैब और टैब दोनों का उपयोग करने की कोशिश की है। माता-पिता के रूप में टैब टैबोडल लेकिन कोई अतिरिक्त टैब शो नहीं है।
import QtQuick 2.0
import QtQuick.LocalStorage 2.0
import Ubuntu.Components 0.1
MainView {
// objectName for functional testing purposes (autopilot-qt5)
id: mainView
objectName: "mainView"
applicationName: "news-feed"
width: units.gu(100)
height: units.gu(75)
Tabs {
id: tabs
anchors.fill: parent
Component.onCompleted: {
mainView.initializeDB();
mainView.saveFeed("BBC News","http://feeds.bbci.co.uk/news/rss.xml");
mainView.saveFeed("Jono Bacon","http://www.jonobacon.org/?feed=rss2");
mainView.saveFeed("The Register", "http://www.theregister.co.uk/headlines.atom");
fillTabs();
}
tools: ToolbarActions {
Action {
objectName: "action"
iconSource: Qt.resolvedUrl("avatar.png")
text: i18n.tr("Tap me!")
onTriggered: {
label.text = i18n.tr("Toolbar tapped")
}
}
}
// First tab begins here
Tab {
id: tabFrontPage
objectName: "tabFrontPage"
title: i18n.tr("Front Page")
// Tab content begins here
page: Page {
Column {
anchors.centerIn: parent
Label {
id: labelFrontPage
text: i18n.tr("This will be the front page \n An aggregation of the top stories from each feed")
}
}
}
}
}
function fillTabs() {
var db = getDatabase();
db.transaction(function(tx) {
var rs = tx.executeSql('SELECT * FROM feeds;');
if (rs.rows.length > 0) {
for(var i = 0; i < rs.rows.length; i++) {
var feedTab = Qt.createQmlObject('import QtQuick 2.0;import Ubuntu.Components 0.1;Tab {anchors.fill: parent;objectName: "Tab";title: i18n.tr("Tab");page: Page {anchors.margins: units.gu(2);Column {anchors.centerIn: parent;Label {id: label;objectName: "label";text: i18n.tr("Tab");}}}}',tabs,"feedTab");
}
} else {
res = "Unknown";
}
})
}
//Storage API
function getDatabase() {
return LocalStorage.openDatabaseSync("news-feed","1.0","StorageDatabase",10000)
}
//Initialise DB tables if not already existing
function initializeDB() {
var db = getDatabase();
db.transaction(function(tx) {
//Create settings table if not existing
tx.executeSql('CREATE TABLE IF NOT EXISTS settings(setting TEXT UNIQUE, value TEXT)');
tx.executeSql('CREATE TABLE IF NOT EXISTS feeds(feedName TEXT UNIQUE, feedURL TEXT UNIQUE)')
});
}
//Write setting to DB
function setSetting(setting,value){
//setting: string - setting name (key)
//value: string - value
var db = getDatabase();
var res = "";
db.transaction(function(tx) {
var rs = tx.executeSql('INSERT OR REPLACE INTO settings VALUES (?,?);',[setting,value]);
//console.log(rs.rowsAffected)
if(rs.rowsAffected > 0) {
res = "OK";
} else {
res = "Error";
}
})
return res;
}
//Read setting from DB
function getSetting(setting) {
var db = getDatabase();
var res="";
db.transaction(function(tx) {
var rs = tx.executeSql('SELECT value FROM settings WHERE setting=?;', [setting]);
if (rs.rows.length > 0) {
res = rs.rows.item(0).value;
} else {
res = "Unknown";
}
})
return res;
}
function saveFeed(feedName, feedURL) {
var db = getDatabase();
var res = "";
db.transaction(function(tx){
var rs = tx.executeSql('INSERT OR REPLACE INTO feeds VALUES (?,?)',[feedName,feedURL]);
//console.log(rs.rowsAffected)
if (rs.rowsAffected > 0) {
res = "OK";
} else {
res = "Error";
}
})
return res;
}
//Return a single feed
function getFeed(feedName) {
var db = getDatabase();
var res = "";
db.transaction(function(tx) {
var rs = tx.executeSql('SELECT feedURL FROM feeds WHERE feedName=?;', [feedName]);
if (rs.rows.length > 0) {
res = rs.rows.item(0).feedURL;
} else {
res = "Unknown";
}
})
return res;
}
//Return all feeds and urls
function getFeeds() {
var db = getDatabase();
var res = "";
db.transaction(function(tx) {
var rs = tx.executeSql('SELECT * FROM feeds;');
if (rs.rows.length > 0) {
return rs;
} else {
res = "Unknown";
}
})
return res;
}
}