objectName_list<<"label_master_ac"<<"label_living_ac"<<"label_dining_ac"<<"label_bathroom_geyser"<<"label_entertainment"
<<"label_heater";
QFile *file = new QFile("E:/label_with_xml_file/labelname.xml");
QMessageBox::warning(this, tr
("Error: Cannot read file"),tr
(qPrintable
(file
->errorString
())));
}
doc.setContent(file);
i=0;
while(!node.isNull())
{
if(node.toElement().tagName() == "label"){
if(node.toElement().attribute("objectName") != "label_master_ac" &&
node.toElement().attribute("objectName") != "label_living_ac" &&
node.toElement().attribute("objectName") != "label_dining_ac" &&
node.toElement().attribute("objectName") != "label_bathroom_geyser"
&& node.toElement().attribute("objectName") != "label_entertainment"
&& node.toElement().attribute("objectName") != "label_heater"){
qDebug()<<"while"<<node.toElement().attribute("objectName");
node = node.nextSibling();
continue;
}
qDebug()<<QString::number(i);
QFont font
("Verdana",
10);
font.setBold(true);
label->setFont(font);
label->setAlignment(Qt::AlignCenter);
label->setFixedHeight(screenHeight/35);
label->setStyleSheet("QLabel { background-color: rgb(240, 240, 240,255); color: rgb(131, 64, 0, 255);}");
label->setObjectName(objectName_list.at(i));
qDebug()<< node.toElement().attribute("objectName");
if(objectName_list.at(i) == "label_master_ac" && node.toElement().attribute("objectName") == "label_master_ac"){
label->setText(node.toElement().text());
grid->addWidget(label, 0,1);
}
if(objectName_list.at(i) == "label_living_ac" && node.toElement().attribute("objectName") == "label_living_ac"){
label->setText(node.toElement().text());
grid->addWidget(label, 0,2);
}
if(objectName_list.at(i) == "label_dining_ac" && node.toElement().attribute("objectName") == "label_dining_ac"){
label->setText(node.toElement().text());
grid->addWidget(label, 0,3);
}
if(objectName_list.at(i) == "label_bathroom_geyser" && node.toElement().attribute("objectName") == "label_bathroom_geyser"){
label->setText(node.toElement().text());
grid->addWidget(label, 4, 1);
}
if(objectName_list.at(i) == "label_entertainment" && node.toElement().attribute("objectName") == "label_entertainment"){
label->setText(node.toElement().text());
grid->addWidget(label, 4, 2);
}
if(objectName_list.at(i) == "label_heater" && node.toElement().attribute("objectName") == "label_heater"){
label->setText(node.toElement().text());
grid->addWidget(label, 4, 3);
}
}
node = node.nextSibling();
i++;
file->seek(0);
}
QStringList objectName_list;
objectName_list<<"label_master_ac"<<"label_living_ac"<<"label_dining_ac"<<"label_bathroom_geyser"<<"label_entertainment"
<<"label_heater";
QFile *file = new QFile("E:/label_with_xml_file/labelname.xml");
if (!file->open(QFile::ReadOnly | QFile::Text)) {
QMessageBox::warning(this, tr("Error: Cannot read file"),tr(qPrintable(file->errorString())));
}
QDomDocument doc;
doc.setContent(file);
QDomElement root = doc.documentElement();
QDomNode node = root.firstChild();
i=0;
while(!node.isNull())
{
if(node.toElement().tagName() == "label"){
if(node.toElement().attribute("objectName") != "label_master_ac" &&
node.toElement().attribute("objectName") != "label_living_ac" &&
node.toElement().attribute("objectName") != "label_dining_ac" &&
node.toElement().attribute("objectName") != "label_bathroom_geyser"
&& node.toElement().attribute("objectName") != "label_entertainment"
&& node.toElement().attribute("objectName") != "label_heater"){
qDebug()<<"while"<<node.toElement().attribute("objectName");
node = node.nextSibling();
continue;
}
qDebug()<<QString::number(i);
QLabel *label = new QLabel(this);
QFont font("Verdana", 10);
font.setBold(true);
label->setFont(font);
label->setAlignment(Qt::AlignCenter);
label->setFixedHeight(screenHeight/35);
label->setStyleSheet("QLabel { background-color: rgb(240, 240, 240,255); color: rgb(131, 64, 0, 255);}");
label->setObjectName(objectName_list.at(i));
qDebug()<< node.toElement().attribute("objectName");
if(objectName_list.at(i) == "label_master_ac" && node.toElement().attribute("objectName") == "label_master_ac"){
label->setText(node.toElement().text());
grid->addWidget(label, 0,1);
}
if(objectName_list.at(i) == "label_living_ac" && node.toElement().attribute("objectName") == "label_living_ac"){
label->setText(node.toElement().text());
grid->addWidget(label, 0,2);
}
if(objectName_list.at(i) == "label_dining_ac" && node.toElement().attribute("objectName") == "label_dining_ac"){
label->setText(node.toElement().text());
grid->addWidget(label, 0,3);
}
if(objectName_list.at(i) == "label_bathroom_geyser" && node.toElement().attribute("objectName") == "label_bathroom_geyser"){
label->setText(node.toElement().text());
grid->addWidget(label, 4, 1);
}
if(objectName_list.at(i) == "label_entertainment" && node.toElement().attribute("objectName") == "label_entertainment"){
label->setText(node.toElement().text());
grid->addWidget(label, 4, 2);
}
if(objectName_list.at(i) == "label_heater" && node.toElement().attribute("objectName") == "label_heater"){
label->setText(node.toElement().text());
grid->addWidget(label, 4, 3);
}
}
node = node.nextSibling();
i++;
file->seek(0);
}
To copy to clipboard, switch view to plain text mode
Bookmarks