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.
  • I iqbalfaheem21

    Still it is getting crashed. I guess there should be some other way.

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

    @iqbalfaheem21

    You could debug it ? ;)

    place a breakpoint in the slot for the Send Email
    button and single step from there.

    That should give us the exact line where it crashes and hopefully also why it crashes :)

    http://doc.qt.io/qtcreator/creator-debugging.html

    I 1 Reply Last reply
    1
    • mrjjM mrjj

      @iqbalfaheem21

      You could debug it ? ;)

      place a breakpoint in the slot for the Send Email
      button and single step from there.

      That should give us the exact line where it crashes and hopefully also why it crashes :)

      http://doc.qt.io/qtcreator/creator-debugging.html

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

      @mrjj

      Okay. I am still unable to do. However, in the .ui file, I found a way that we can just drag n drop a treewidget and add the items. I just need to do one thing now. i.e iteration and send emails to the checked ones. The items can be accessed by ui->treeWidget. I can send emails to the selected ones by:
      void MainWindow::on_pushButton_clicked()
      {
      //Send Email

      QList<QTreeWidgetItem *> itemList;
         itemList = ui->treeWidget->selectedItems();
         QString strTo = "mailto:";
      
         foreach(QTreeWidgetItem *item, itemList)
         {
          if(item->checkState(0)== Qt::Checked)
             strTo.append(item->text(0)+";");
      

      }
      { ui->treeWidget->;

        }
             openUrl->openUrl(QUrl(strTo));
      

      }

      But I dont want the selection functionality. I only want checked functionality. That means, if an item is checked, email will be send to it.
      Please provide the code for the iteration of items in the treewidget (iteration of all, parents and child).

      mrjjM 1 Reply Last reply
      0
      • I iqbalfaheem21

        @mrjj

        Okay. I am still unable to do. However, in the .ui file, I found a way that we can just drag n drop a treewidget and add the items. I just need to do one thing now. i.e iteration and send emails to the checked ones. The items can be accessed by ui->treeWidget. I can send emails to the selected ones by:
        void MainWindow::on_pushButton_clicked()
        {
        //Send Email

        QList<QTreeWidgetItem *> itemList;
           itemList = ui->treeWidget->selectedItems();
           QString strTo = "mailto:";
        
           foreach(QTreeWidgetItem *item, itemList)
           {
            if(item->checkState(0)== Qt::Checked)
               strTo.append(item->text(0)+";");
        

        }
        { ui->treeWidget->;

          }
               openUrl->openUrl(QUrl(strTo));
        

        }

        But I dont want the selection functionality. I only want checked functionality. That means, if an item is checked, email will be send to it.
        Please provide the code for the iteration of items in the treewidget (iteration of all, parents and child).

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

        @iqbalfaheem21

        Hi @VRonin already gave you the code in
        https://forum.qt.io/topic/71237/adding-email-functionality-in-qtreewidget-urgent-reply-needed/7

        You cannot use selectedItems(); since you want the Checked ones.

        You need to do it recursively as @VRonin shows.
        for(int i=0;i<model->rowCount(parent );++i){
        ....
        if(model->hasChildren(currIdx)) ...
        result.append(getCheckedAdresses(model,currIdx)); <<<<< here it calls itself again. So it processes its children too, and its children and its children and..
        ....

        I 1 Reply Last reply
        2
        • mrjjM mrjj

          @iqbalfaheem21

          Hi @VRonin already gave you the code in
          https://forum.qt.io/topic/71237/adding-email-functionality-in-qtreewidget-urgent-reply-needed/7

          You cannot use selectedItems(); since you want the Checked ones.

          You need to do it recursively as @VRonin shows.
          for(int i=0;i<model->rowCount(parent );++i){
          ....
          if(model->hasChildren(currIdx)) ...
          result.append(getCheckedAdresses(model,currIdx)); <<<<< here it calls itself again. So it processes its children too, and its children and its children and..
          ....

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

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

          if(model->hasChildren(currIdx)) ...

          I did it in other way. Simple and easy.

          QString strTo = "mailto:";
          QTreeWidgetItemIterator item(ui->treeWidget);
          while (*item) {
          if ((*item)->checkState(0) == Qt::Checked)
          strTo.append((*item)->text(0)+";");
          ++item;
          }
          openUrl->openUrl(QUrl(strTo));

          mrjjM 1 Reply Last reply
          1
          • I iqbalfaheem21

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

            if(model->hasChildren(currIdx)) ...

            I did it in other way. Simple and easy.

            QString strTo = "mailto:";
            QTreeWidgetItemIterator item(ui->treeWidget);
            while (*item) {
            if ((*item)->checkState(0) == Qt::Checked)
            strTo.append((*item)->text(0)+";");
            ++item;
            }
            openUrl->openUrl(QUrl(strTo));

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

            @iqbalfaheem21
            super.

            I 1 Reply Last reply
            1
            • mrjjM mrjj

              @iqbalfaheem21
              super.

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

              Ouch. One more functionality needed to be added. I request all my folks to please assist me in this as well.

              Now I need to get the data from the SharePoint site. So what can be the code in Qt that can get the data from SharePoint and work in the same manner. So, in other words, it will get the data from SharePoint, and display all the data from it. Then whatever is checked from the tree will be included with the "mailto:" string.
              So basically, no hard coding but getting the data from Sharepoint.
              Pleae let mek now.

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

                Hi

                • get the data from the SharePoint site
                  From rest service ?
                  From SQL server ?
                  From ?
                  What data ?

                Unless the SharePoint devs knows 100% what you mean, i doubt
                there be many answer :)
                Maybe I just dont know SharePoint well enough :)

                I 1 Reply Last reply
                1
                • mrjjM mrjj

                  Hi

                  • get the data from the SharePoint site
                    From rest service ?
                    From SQL server ?
                    From ?
                    What data ?

                  Unless the SharePoint devs knows 100% what you mean, i doubt
                  there be many answer :)
                  Maybe I just dont know SharePoint well enough :)

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

                  @mrjj

                  I am linking the sharepoint data with an access file. Now I need to connect the access file with the Qt application that I made. So I need the code to connect to the access file, read the data from there and display it.. Also let me know where to write the code. In the header file, main.cpp, mainwindow.cpp or somewhere else.

                  1 Reply Last reply
                  0
                  • 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

                                          • Login

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