#include "widget.h"#include <QDir>#include <QString>#include <QDebug>#include <QGridLayout>void calcRows();int dir = 0;Widget::Widget(QWidget *parent) : QWidget(parent){ sdb = QSqlDatabase::addDatabase("QSQLITE"); sdb.setDatabaseName("D:/Programming/release/FuOrgProjectFirstRelease/myDB.sqlite"); sdb.open(); QSqlQuery a_query; if(sdb.isOpen()) { qDebug() << "Yeah"; } else { qDebug() << "noob"; qDebug() << sdb.lastError().text(); } QString str = "SELECT * FROM FuOrg"; a_query.exec(str); QSqlRecord rec = a_query.record(); QString addressIcon; QString addressExe; int i = 0; while(a_query.next()) { i++; } QString exeFile[i]; QString icoFile[i]; int numeric=0; qDebug() << i; a_query.first(); a_query.previous(); while(a_query.next()) { exeFile[numeric] = a_query.value(rec.indexOf("addressExe")).toString(); icoFile[numeric] = a_query.value(rec.indexOf("addressIcon")).toString(); numeric++; } numeric=0; testWidgetList = new QListWidget(); testWidgetList->setViewMode(QListView::IconMode); testWidgetList->setResizeMode(QListView::Adjust); testWidgetList->setDragEnabled(false); while (numeric < i) { testItemWidget = new QListWidgetItem(QIcon(icoFile[numeric]) , QString(""), testWidgetList); testWidgetList->addItem(testItemWidget); testItemWidget->setData(numeric,""); numeric++; } QGridLayout *testlay = new QGridLayout; testlay->addWidget(testWidgetList); setLayout(testlay); setWindowTitle(tr("Fuorg"));}Widget::~Widget(){ }
...private slots: void itemDoubleClicked(QListWidgetItem *item);
Widget::Widget(QWidget *parent) : QWidget(parent){ sdb = QSqlDatabase::addDatabase("QSQLITE"); sdb.setDatabaseName("D:/Programming/release/FuOrgProjectFirstRelease/myDB.sqlite"); sdb.open(); QSqlQuery a_query; if(sdb.isOpen()) { qDebug() << "Yeah"; } else { qDebug() << "noob"; qDebug() << sdb.lastError().text(); } QString str = "SELECT * FROM FuOrg"; a_query.exec(str); QSqlRecord rec = a_query.record(); testWidgetList = new QListWidget(); testWidgetList->setViewMode(QListView::IconMode); testWidgetList->setResizeMode(QListView::Adjust); testWidgetList->setDragEnabled(false);// заполняем QListWidget while(a_query.next()) { QString addressExe = a_query.value(rec.indexOf("addressExe")).toString(); QString addressIcon = a_query.value(rec.indexOf("addressIcon")).toString(); QListWidgetItem *newItem = new QListWidgetItem(QIcon(addressIcon), QString("")); newItem->setData(32, addressExe); // сохраняем путь к ехе testWidgetList->addItem(newItem); }// подключаем сигнал connect(testWidgetList, SIGNAL(itemDoubleClicked(QListWidgetItem*)), SLOT(itemDoubleClicked(QListWidgetItem))); QGridLayout *testlay = new QGridLayout; testlay->addWidget(testWidgetList); setLayout(testlay); setWindowTitle(tr("Fuorg"));}void Widget::itemDoubleClicked(QListWidgetItem *item){ QString pathExe = item.data(32).toString(); // получаем путь к ехе QProcess::startDetached(pathExe);}