Adding email functionality in QtreeWidget--Urgent reply needed
-
@iqbalfaheem21
You do it like any other database
http://doc.qt.io/qt-5/qsqldatabase.html
the connect line is different. read the docs for it.
db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};FIL={MS Access};DBQ=c:/test.accdb");then use
http://doc.qt.io/qt-5/qsqlquery.html
to read data.
QSqlQuery query("SELECT country FROM artist");
while (query.next()) {
QString country = query.value(0).toString();
doSomething(country);
} -
I am able to connect to the database. Now I need to call the data from the database in such a way that it is displayed in a tree format. Like parent child. Just like if we use filesystem model, all the drives and folders are displayed.
And now if I want to iterate I cannot do that because I am using treeview not treeWidget. So I cant use QtreeWidgetItemIterator. So how to iterate also is a question for me. -
When you are using a view, you must use a model.
The widget version is item based and has hidden model
for that but A view wants a model from you or
one of the predefined
http://doc.qt.io/qt-5/sql-model.htmlIf read-only is ok then
http://doc.qt.io/qt-5/qsqlquerymodel.html#details
might be useful. -
I only need a read model. But when it reads from the database, it should display the data in treewidget format. Dont know how to do that. It is easy to display in rows and columns, but tough to display in tree. Kindly assist.
-
You need to execute the query manually and add the data to the model or widget. I have an example using a QStandardItemModel here: https://github.com/VSRonin/FXhelper/blob/master/FXhelperApp/PortfoliosTab.cpp#L4220
-
@VRonin said in Adding email functionality in QtreeWidget--Urgent reply needed:
using
But using QStandardItemModel will compel me to specify the data. For example, reportsto name("John").QStandardItem(0,1,"Adam"); I want a general code that will keep working fine even if the employees changes. I need to do mapping and dont know how to do it. Any example please?
-
@iqbalfaheem21 said in Adding email functionality in QtreeWidget--Urgent reply needed:
But using QStandardItemModel will compel me to specify the data
No, common misconception though.
you can use QStandardItem::setData to specify the content of a single item or, and this is what I suggest, stick with just using QAbstactItemModel interface either explicitly (declaring the model something like:QAbstactItemModel *model =new QStandardItemModel(parent);
) or limiting yourself in the methods you call. in this case you can useQAbstactItemModel::insertRows
,QAbstactItemModel::insertColumns
andQAbstactItemModel::setData
to populate your model.The explicit use of the interface also allows you, in case further into development you realise you QStandardItemModel is too slow or doesn't suit your needs, to change the model just by changing the constructor call (the line with new) and everything will work out of the box
@iqbalfaheem21 said in Adding email functionality in QtreeWidget--Urgent reply needed:
Any example please?
I linked it above, https://github.com/VSRonin/FXhelper/blob/master/FXhelperApp/PortfoliosTab.cpp#L4220
-
Okay just help me in the code that will index the parent child mapping. Below code I got online. Tried to implement it, but in vain.
QSqlQuery q; QStandardItemModel *myModel; q = db->atpSelect("SELECT * FROM group_tbl"); myModel->clear(); myModel->setColumnCount(3); myModel->setHeaderData(0, Qt::Horizontal,"Name"); myModel->setHeaderData(1, Qt::Horizontal,"ID"); myModel->setHeaderData(2, Qt::Horizontal,"Parent"); QStandardItem *parent; while(q.next()) { int id = q.value(0).toInt(); QString name = q.value(1).toString(); int parentId = q.value(2).toInt(); QStandardItem *pId = new QStandardItem(QString::number(id)); QStandardItem *pName = new QStandardItem(name); QStandardItem *pParentId = new QStandardItem(QString::number(parentId)); QList<QStandardItem *> row; row.append(pName); row.append(pId); row.append(pParentId); rowItemMap.insert(id, pName); if (parentId == 0 && id != 0) { myModel->appendRow(row); } else { parent = rowItemMap[parentId]; parent->appendRow(row); } }
-
You can add email functionality by Office 365 web part or SharePoint designer. With the help of web part, you can easily add the email id after implementing the SharePoint or Cloud.