1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| void MainWindow::createActions()
{
QDomDocument doc;
QFile f("text.xml");
f.open(QIODevice::ReadOnly);
doc.setContent(&f);
f.close();
QDomElement root=doc.documentElement();
QDomElement child=root.firstChild().toElement();
//compteur d'actions
i=0;
QSignalMapper *signalMapper = new QSignalMapper(this);
//tant qu'il y a un élément dans le menu
while(!child.isNull())
{
//
if (child.tagName() == "element")
{
//on parcours l'élémént
QDomElement grandChild=child.firstChild().toElement();
while(!grandChild.isNull())
{
//si c'est son nom, on crée une action dont le nom sera le nom du raccourci
if (grandChild.tagName() == "nom")
{
QString nom=grandChild.text();
//temp=grandChild.text();
list.append(new QAction((nom),this));
}
grandChild = grandChild.nextSibling().toElement();
//si c'est le path, on associe l'action définie avant avec l'action de lancement de programme
if (grandChild.tagName() == "path")
{
QString path=grandChild.text();
QAction *act = list[i];
//on utilise un mapper pour transmettre le path à Launch()
connect(act,SIGNAL(triggered()),signalMapper,SLOT(map()));
signalMapper->setMapping(act, path);
connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(Launch(const QString &)));
}
grandChild = grandChild.nextSibling().toElement();
}
child = child.nextSibling().toElement();
i++;
//ts<<i;
} |