Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Adding email functionality in QtreeWidget--Urgent reply needed
Forum Updated to NodeBB v4.3 + New Features

Adding email functionality in QtreeWidget--Urgent reply needed

Scheduled Pinned Locked Moved Unsolved General and Desktop
37 Posts 5 Posters 11.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #21

    Ok, what is "the access file"
    a db file, a text file or what is it?

    I 1 Reply Last reply
    1
    • mrjjM mrjj

      Ok, what is "the access file"
      a db file, a text file or what is it?

      I Offline
      I Offline
      iqbalfaheem21
      wrote on last edited by
      #22

      @mrjj

      A .accdb file

      mrjjM 1 Reply Last reply
      0
      • I iqbalfaheem21

        @mrjj

        A .accdb file

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #23

        @iqbalfaheem21 said in Adding email functionality in QtreeWidget--Urgent reply needed:

        .accdb

        "ACCDB files can be opened with Microsoft Access (version 2007 and newer)."

        So you need to use install driver and set it up.
        then you can use

        db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};FIL={MS Access};DBQ=c:/test.accdb");

        https://www.microsoft.com/en-us/download/details.aspx?id=13255

        You might need some ODBC also. Not sure. Did Not use Access for many years.

        Also pay HUUUUUUUUUUUUUUGE notice to the connection string. its always an issue :)
        https://www.connectionstrings.com/access-2007/#p127

        If you run into issue, there are many posts on google and this forum on how to use Access with Qt.

        I 1 Reply Last reply
        2
        • mrjjM mrjj

          @iqbalfaheem21 said in Adding email functionality in QtreeWidget--Urgent reply needed:

          .accdb

          "ACCDB files can be opened with Microsoft Access (version 2007 and newer)."

          So you need to use install driver and set it up.
          then you can use

          db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};FIL={MS Access};DBQ=c:/test.accdb");

          https://www.microsoft.com/en-us/download/details.aspx?id=13255

          You might need some ODBC also. Not sure. Did Not use Access for many years.

          Also pay HUUUUUUUUUUUUUUGE notice to the connection string. its always an issue :)
          https://www.connectionstrings.com/access-2007/#p127

          If you run into issue, there are many posts on google and this forum on how to use Access with Qt.

          I Offline
          I Offline
          iqbalfaheem21
          wrote on last edited by
          #24

          @mrjj
          Can you send me the exact possible code for this?

          mrjjM 1 Reply Last reply
          0
          • I iqbalfaheem21

            @mrjj
            Can you send me the exact possible code for this?

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by mrjj
            #25

            @iqbalfaheem21
            That is really not possible as you will need a ODBC + Access driver installed and have exact accdb
            to open etc. This you must master yourself.

            You could start with small sample and try to get a database open.
            There are many examples on the internet but you could start
            practice with the ones from Qt

            http://doc.qt.io/qt-5/examples-sql.html

            and try with with sqllite.
            then when you understand how database and
            http://doc.qt.io/qt-5/qsqlquery.html
            works then try to open the accdb file.
            You will need this to read the data anyways. You can also ask here for help but
            you need a bit of SQL and database+qsqlquery

            I 1 Reply Last reply
            1
            • mrjjM mrjj

              @iqbalfaheem21
              That is really not possible as you will need a ODBC + Access driver installed and have exact accdb
              to open etc. This you must master yourself.

              You could start with small sample and try to get a database open.
              There are many examples on the internet but you could start
              practice with the ones from Qt

              http://doc.qt.io/qt-5/examples-sql.html

              and try with with sqllite.
              then when you understand how database and
              http://doc.qt.io/qt-5/qsqlquery.html
              works then try to open the accdb file.
              You will need this to read the data anyways. You can also ask here for help but
              you need a bit of SQL and database+qsqlquery

              I Offline
              I Offline
              iqbalfaheem21
              wrote on last edited by
              #26

              @mrjj

              Forget about SharePoint. Just a code to read data from MS Access file in Qt application.

              mrjjM 1 Reply Last reply
              0
              • I iqbalfaheem21

                @mrjj

                Forget about SharePoint. Just a code to read data from MS Access file in Qt application.

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #27

                @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 1 Reply Last reply
                2
                • mrjjM mrjj

                  @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 Offline
                  I Offline
                  iqbalfaheem21
                  wrote on last edited by
                  #28

                  @mrjj

                  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.

                  1 Reply Last reply
                  1
                  • mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by mrjj
                    #29

                    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.html

                    If read-only is ok then
                    http://doc.qt.io/qt-5/qsqlquerymodel.html#details
                    might be useful.

                    I 1 Reply Last reply
                    1
                    • mrjjM mrjj

                      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.html

                      If read-only is ok then
                      http://doc.qt.io/qt-5/qsqlquerymodel.html#details
                      might be useful.

                      I Offline
                      I Offline
                      iqbalfaheem21
                      wrote on last edited by
                      #30

                      @mrjj

                      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.

                      1 Reply Last reply
                      0
                      • VRoninV Offline
                        VRoninV Offline
                        VRonin
                        wrote on last edited by
                        #31

                        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

                        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                        ~Napoleon Bonaparte

                        On a crusade to banish setIndexWidget() from the holy land of Qt

                        I 1 Reply Last reply
                        1
                        • VRoninV VRonin

                          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

                          I Offline
                          I Offline
                          iqbalfaheem21
                          wrote on last edited by
                          #32

                          @VRonin

                          I am able to connect to the database. But how to get the data in a tree view. Do I need to pull the data in a treeview format?
                          the data in the database has no parent child relation. I am lost?

                          1 Reply Last reply
                          0
                          • VRoninV Offline
                            VRoninV Offline
                            VRonin
                            wrote on last edited by
                            #33

                            There is no magically working solution, you have to iterate through each record of the query and build your tree model manually (using QStandardItemModel?)

                            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                            ~Napoleon Bonaparte

                            On a crusade to banish setIndexWidget() from the holy land of Qt

                            I 1 Reply Last reply
                            1
                            • VRoninV VRonin

                              There is no magically working solution, you have to iterate through each record of the query and build your tree model manually (using QStandardItemModel?)

                              I Offline
                              I Offline
                              iqbalfaheem21
                              wrote on last edited by
                              #34

                              @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?

                              VRoninV 1 Reply Last reply
                              0
                              • I iqbalfaheem21

                                @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?

                                VRoninV Offline
                                VRoninV Offline
                                VRonin
                                wrote on last edited by VRonin
                                #35

                                @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 use QAbstactItemModel::insertRows, QAbstactItemModel::insertColumns and QAbstactItemModel::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

                                "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                                ~Napoleon Bonaparte

                                On a crusade to banish setIndexWidget() from the holy land of Qt

                                I 1 Reply Last reply
                                2
                                • VRoninV VRonin

                                  @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 use QAbstactItemModel::insertRows, QAbstactItemModel::insertColumns and QAbstactItemModel::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

                                  I Offline
                                  I Offline
                                  iqbalfaheem21
                                  wrote on last edited by VRonin
                                  #36

                                  @VRonin

                                  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);
                                  }
                                  }
                                  
                                  1 Reply Last reply
                                  0
                                  • A Offline
                                    A Offline
                                    amikate
                                    wrote on last edited by
                                    #37

                                    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.

                                    1 Reply Last reply
                                    0

                                    • Login

                                    • Login or register to search.
                                    • First post
                                      Last post
                                    0
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular
                                    • Users
                                    • Groups
                                    • Search
                                    • Get Qt Extensions
                                    • Unsolved