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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #3

    I have another problem with respect to sending more than one emails.
    I can select multiple rows via mouse or keyboard from the tree, but when I click send email, it sends only to the currentItem. I tried to use selecteditems, but in vain. Below is how the code looks for the email part. I think some function is missing that allows me to send the emails to all the selected Items. Note: data(0,0) is the first column that has the email addresses.

    QString strTo = "mailto:";
    strTo.append(ui->treeWidget->currentItem()->data(0,0).toString());

        openUrl->openUrl(QUrl(strTo));
    
    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #4

      Hi

      • I tried to use selecteditems, but in vain.

      something like ?

      void SendMail(QString email) {
      QString strTo = "mailto:";
      strTo.append(email);
      openUrl->openUrl(QUrl(strTo));
      }

      QList<QTreeWidgetItem *> itemList;
      itemList = this->MyTree->selectedItems();
      foreach(QTreeWidgetItem *item, itemList)
      {
      QString str = item->data(0,0).toString());
      SendEmail(str);
      }

      1 Reply Last reply
      1
      • I Offline
        I Offline
        iqbalfaheem21
        wrote on last edited by VRonin
        #5

        Thanks for the reply. It worked. Lastly I need to add some more functionality. I added check boxed to each item. Now If I check the root I need all the items to be checked. If I select a child all the subchilds of it should be checked. Moreover, after clicking the send email, it should send the email to all the checked boxes. Also, I dont need the selection feature (I need only checked feature)
        Below is the code I am struggling with:

        void Dialog::on_pushButton_clicked()
        
        {
             //Send Email
        
            QList<QTreeWidgetItem *> itemList;
          itemList = ui->treeWidget->selectedItems();
        
            QString strTo = "mailto:";
        
           foreach(QTreeWidgetItem *item, itemList)
           {
         //    if(item->text(0)=="Organization")
            //     continue;
        
               if(item->checkState(0)== Qt::Checked)
        {
             
                  strTo.append(item->text(0)+";");
            }
        }
            openUrl->openUrl(QUrl(strTo));
        }
        
        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #6

          Hi
          Ok checked is not the same as selected so

          • itemList = ui->treeWidget->selectedItems();

          is not really what u want as that is selected not checked so unless they are ALSO selected
          the list is empty.

          You can use
          http://doc.qt.io/qt-5/qtreewidgetitemiterator.html#details

          To process all checked items.

          Alternatively this is also possible:
          http://stackoverflow.com/questions/9986231/getting-a-qtreewidgetitem-list-again-from-qtreewidget

          doStuffWithEveryItemInMyTree( tree->invisibleRootItem() );
          
          void doStuffWithEveryItemInMyTree( QTreeWidgetItem *item )
          {
              // Do something with item ...
          
              for( int i = 0; i < item->childCount(); ++i )
                  doStuffWithEveryItemInMyTree( item->child(i) );
          }
          
          1 Reply Last reply
          1
          • VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by VRonin
            #7
            QStringList getCheckedAdresses(const QAbstractItemModel* model, const QModelIndex& parent = QModelIndex()){
                QStringList result;
                if(!model)
                    return result;
                if(parent.isValid()){
                    if(parent.model()!=model)
                        return result;
                }
                for(int i=0;i<model->rowCount(parent );++i){
                    for(int j=0;j<model->columnCount(parent );++j){
                        const QModelIndex currIdx=model->index(i,j,parent);
                        if(currIdx.data(Qt::CheckStateRole).toInt())
                            result.append(currIdx.data().toString());
                        if(model->hasChildren(currIdx))
                            result.append(getCheckedAdresses(model,currIdx));
                    }
                }
                return result;
            }
            

            then use it in

            const QStringList adresses = getCheckedAdresses(ui->treeWidget->model());
            if(!adresses.isEmpty())
            openUrl->openUrl(QUrl("mailto:"+adresses.join(';')));
            

            "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

            1 Reply Last reply
            2
            • I Offline
              I Offline
              iqbalfaheem21
              wrote on last edited by VRonin
              #8

              Okay. I am totally lost. Below is my complete code. So anyone please give me the exact solution according to my scenario. That will be a great help.

              Please note: I want 3 functionalities.

              1. If I check the parent node, all the children under get be checked. Later when I click send email, the email be sent to all the checked ones.

              2. If I check a child node, any subchild under it be checked. Later when I click send email, the email be sent to all the checked ones.

              3. If I check a child node, that does not have any child, only it should be checked. Later when I click send email, the email be sent to all the checked ones.

              Also, I have made lined between different items. There are four levels.

              1. Org (Clicking this will select all)
                2) Senior Manager (Clicking this will select all managers only)
                3) Manager (Clicking this will select all employees under him)
                4) Employee (Clicking this will select only him)
              #include "dialog.h"
              #include "ui_dialog.h"
              #include <QtCore>
              #include <QtGui>
              #include <QTreeWidgetItem>
              #include <iostream>
              #include <QLabel>
              #include <QDesktopServices>
              #include <QList>
              #include <QApplication>
              #include <QAbstractItemView>
              
              
              Dialog::Dialog(QWidget *parent) :
                  QMainWindow(parent),
                  ui(new Ui::Dialog)
              {
                  ui->setupUi(this);
              
                  ui->treeWidget->setColumnCount(6);
                  ui->treeWidget->setColumnWidth(0,200);
                  ui->treeWidget->setColumnWidth(1,200);
                  ui->treeWidget->setColumnWidth(2,200);
                  ui->treeWidget->setColumnWidth(3,200);
                  ui->treeWidget->setColumnWidth(4,200);
                  ui->treeWidget->setColumnWidth(5,200);
              
                  ui->treeWidget->setHeaderLabels(QStringList()
                         << Email<<"First Name"<< "Last Name" <<"Role"<<"Boss "<< "Desk";
              
                  AddRoot("Org","\0","\0", "\0", "\0","\0");
              
              }
              
              void Dialog::AddRoot( QString email, QString Fname, QString Lname,  QString Role, QString ReportsTo, QString Desk;
              {
                      QTreeWidgetItem *itm =  new QTreeWidgetItem(ui->treeWidget);
              
                      itm->setText(0,Email);
                      itm->setText(1,Fname);
                      itm->setText(2,Lname);
                      itm->setText(3,Role);
                      itm->setText(4, Boss);
                      itm->setTextDesk
                      itm->setCheckState(0,Qt::Unchecked);
                      ui->treeWidget->addTopLevelItem(itm);
              
                      AddChild(itm,"abc","qqq","www", "zzz", "ddds","111");
              
                      ui->treeWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
                      ui->treeWidget->setSelectionMode(QAbstractItemView::MultiSelection);
              }
              void Dialog::AddChild(QTreeWidgetItem *parent,  QString Email, QString Fname, QString Lname,  QString Role, QString Boss, QString Desk)
              {
                  QTreeWidgetItem *itm = new QTreeWidgetItem();
                  itm->setText(0,Email);
                  itm->setText(1,Fname);
                  itm->setText(2,Lname);
                  itm->setText(3,Role);
                  itm->setText(4,Boss);
                  itm->setText(5,Desk);
                  itm->setFlags(itm->flags() | Qt::ItemIsUserCheckable);
                  itm->setCheckState(0,Qt::Unchecked);
                  parent->addChild(itm);
              
                 QTreeWidgetItem *k_itm=new QTreeWidgetItem(itm,QStringList() <<"bbb"<<"vvv"<<"1111\n");
                 k_itm->setCheckState(0,Qt::Unchecked);
                 QTreeWidgetItem *s_itm=new QTreeWidgetItem(itm,QStringList() <<"ccc"<<"lll"<<"1111\n");
                 s_itm->setCheckState(0,Qt::Unchecked);
                 QTreeWidgetItem *e_itm=new QTreeWidgetItem(itm, QStringList()<< "ddd"<<"oooo"<<"1111\n");
                 e_itm->setCheckState(0,Qt::Unchecked);
                 QTreeWidgetItem *y_itm=new QTreeWidgetItem(itm, QStringList()<< "eee"<<"jjj"<<"1111\n");
                 y_itm->setCheckState(0,Qt::Unchecked);
                 QTreeWidgetItem *sk_itm=new QTreeWidgetItem(itm, QStringList()<< "fff"<<"rrr""1111\n");
                 sk_itm->setCheckState(0,Qt::Unchecked);
                 QTreeWidgetItem *b_itm=new QTreeWidgetItem(itm, QStringList()<< "ggg"<<"eee"<<"1111");
                 b_itm->setCheckState(0,Qt::Unchecked);
                 QTreeWidgetItem *j_itm=new QTreeWidgetItem(itm, QStringList()<< "hhh"<<"eee"<<"1111 \n");
                 j_itm->setCheckState(0,Qt::Unchecked);
                 QTreeWidgetItem *h_itm=new QTreeWidgetItem(itm,QStringList() <<"iii"<<"yyy"<<"1111 \n");
                 h_itm->setCheckState(0,Qt::Unchecked);
                 new QTreeWidgetItem(itm,QStringList() <<"jjj"<<"xxx"<<"1111 \n");
              
              
                 QTreeWidgetItem *qqq = new QTreeWidgetItem(*k_itm,QStringList() <<"qqq"<<"qwqe"<<"1111");
                   qqq->setCheckState(0,Qt::Unchecked);
              
                  QTreeWidgetItem *www =new QTreeWidgetItem(s_itm,QStringList() <<"www"<<"nun"<<"1111");
                  www->setCheckState(0,Qt::Unchecked);
              
                  QTreeWidgetItem *eee= new QTreeWidgetItem(e_itm,QStringList() <<"eee"<<"vvv"<<"1111");
                  eee->setCheckState(0,Qt::Unchecked);
              
              
              
                  QTreeWidgetItem *nnn = new QTreeWidgetItem(e_itm,QStringList() <<"nnn"<<"nhn"<<"1111");
                  nnn->setCheckState(0,Qt::Unchecked);
              
                  QTreeWidgetItem *pop = new QTreeWidgetItem(y_itm,QStringList() <<"pop"<<"fff"<<"1111 ");
                  pop->setCheckState(0,Qt::Unchecked);
              
                 QTreeWidgetItem *zaz = new QTreeWidgetItem(sk_itm,QStringList() <<"zaz"<<"fgf"<<"1111");
                 zaz->setCheckState(0,Qt::Unchecked);
              
                 QTreeWidgetItem *xsxs = new QTreeWidgetItem(b_itm,QStringList() <<"xsxs"<<"yhgf"<<"1111 ");
                 xsxs->setCheckState(0,Qt::Unchecked);
              
                 QTreeWidgetItem *cdcd = new QTreeWidgetItem(j_itm,QStringList() <<"cdcd"<<"poj"<<"1111");
                 cdcd->setCheckState(0,Qt::Unchecked);
              
                  QTreeWidgetItem *vfvf = new QTreeWidgetItem(h_itm,QStringList() <<"vfvf"<<"fvf"<<"1111");
                  vfvf->setCheckState(0,Qt::Unchecked);
                 
              }
              Dialog::~Dialog()
              {
                  delete ui;
              }
              
              void Dialog::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)
                      //  if(item->checkState(0)== Qt::Checked){
              
              
                      strTo.append(item->text(0)+";");
              }
                 // if(item->checkState(0)== Qt::Checked)
               //   {         ui->treeWidget->;
              
               //   }
                      openUrl->openUrl(QUrl(strTo));
              }
              
              I 1 Reply Last reply
              0
              • VRoninV Offline
                VRoninV Offline
                VRonin
                wrote on last edited by VRonin
                #9

                Later when I click send email, the email be sent to all the checked ones.

                put my getCheckedAdresses function from above somewhere in your code (a private member of Dialog or just pasting it at the top of the .cpp file, after the includes)

                then delete everything in Dialog::on_pushButton_clicked and paste

                const QStringList adresses = getCheckedAdresses(ui->treeWidget->model());
                if(!adresses.isEmpty())
                openUrl->openUrl(QUrl("mailto:"+adresses.join(';')));
                

                for the parent-checks-the-child I don't think it's that straightforward, you'll probably have to store the check state twice in two roles then when dataChange signal is emitted form ui->treeWidget->model() you have to check if the 2 check roles match and if they don't then the check canged and you should check the cildren. All this because QStandrdItemModel, which runs under the hood of QTreeWidget, sends always an empty vector as third argument of dataChange. I hope some of the ginuses roaming around here have a better solution

                "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

                1 Reply Last reply
                2
                • I iqbalfaheem21

                  Okay. I am totally lost. Below is my complete code. So anyone please give me the exact solution according to my scenario. That will be a great help.

                  Please note: I want 3 functionalities.

                  1. If I check the parent node, all the children under get be checked. Later when I click send email, the email be sent to all the checked ones.

                  2. If I check a child node, any subchild under it be checked. Later when I click send email, the email be sent to all the checked ones.

                  3. If I check a child node, that does not have any child, only it should be checked. Later when I click send email, the email be sent to all the checked ones.

                  Also, I have made lined between different items. There are four levels.

                  1. Org (Clicking this will select all)
                    2) Senior Manager (Clicking this will select all managers only)
                    3) Manager (Clicking this will select all employees under him)
                    4) Employee (Clicking this will select only him)
                  #include "dialog.h"
                  #include "ui_dialog.h"
                  #include <QtCore>
                  #include <QtGui>
                  #include <QTreeWidgetItem>
                  #include <iostream>
                  #include <QLabel>
                  #include <QDesktopServices>
                  #include <QList>
                  #include <QApplication>
                  #include <QAbstractItemView>
                  
                  
                  Dialog::Dialog(QWidget *parent) :
                      QMainWindow(parent),
                      ui(new Ui::Dialog)
                  {
                      ui->setupUi(this);
                  
                      ui->treeWidget->setColumnCount(6);
                      ui->treeWidget->setColumnWidth(0,200);
                      ui->treeWidget->setColumnWidth(1,200);
                      ui->treeWidget->setColumnWidth(2,200);
                      ui->treeWidget->setColumnWidth(3,200);
                      ui->treeWidget->setColumnWidth(4,200);
                      ui->treeWidget->setColumnWidth(5,200);
                  
                      ui->treeWidget->setHeaderLabels(QStringList()
                             << Email<<"First Name"<< "Last Name" <<"Role"<<"Boss "<< "Desk";
                  
                      AddRoot("Org","\0","\0", "\0", "\0","\0");
                  
                  }
                  
                  void Dialog::AddRoot( QString email, QString Fname, QString Lname,  QString Role, QString ReportsTo, QString Desk;
                  {
                          QTreeWidgetItem *itm =  new QTreeWidgetItem(ui->treeWidget);
                  
                          itm->setText(0,Email);
                          itm->setText(1,Fname);
                          itm->setText(2,Lname);
                          itm->setText(3,Role);
                          itm->setText(4, Boss);
                          itm->setTextDesk
                          itm->setCheckState(0,Qt::Unchecked);
                          ui->treeWidget->addTopLevelItem(itm);
                  
                          AddChild(itm,"abc","qqq","www", "zzz", "ddds","111");
                  
                          ui->treeWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
                          ui->treeWidget->setSelectionMode(QAbstractItemView::MultiSelection);
                  }
                  void Dialog::AddChild(QTreeWidgetItem *parent,  QString Email, QString Fname, QString Lname,  QString Role, QString Boss, QString Desk)
                  {
                      QTreeWidgetItem *itm = new QTreeWidgetItem();
                      itm->setText(0,Email);
                      itm->setText(1,Fname);
                      itm->setText(2,Lname);
                      itm->setText(3,Role);
                      itm->setText(4,Boss);
                      itm->setText(5,Desk);
                      itm->setFlags(itm->flags() | Qt::ItemIsUserCheckable);
                      itm->setCheckState(0,Qt::Unchecked);
                      parent->addChild(itm);
                  
                     QTreeWidgetItem *k_itm=new QTreeWidgetItem(itm,QStringList() <<"bbb"<<"vvv"<<"1111\n");
                     k_itm->setCheckState(0,Qt::Unchecked);
                     QTreeWidgetItem *s_itm=new QTreeWidgetItem(itm,QStringList() <<"ccc"<<"lll"<<"1111\n");
                     s_itm->setCheckState(0,Qt::Unchecked);
                     QTreeWidgetItem *e_itm=new QTreeWidgetItem(itm, QStringList()<< "ddd"<<"oooo"<<"1111\n");
                     e_itm->setCheckState(0,Qt::Unchecked);
                     QTreeWidgetItem *y_itm=new QTreeWidgetItem(itm, QStringList()<< "eee"<<"jjj"<<"1111\n");
                     y_itm->setCheckState(0,Qt::Unchecked);
                     QTreeWidgetItem *sk_itm=new QTreeWidgetItem(itm, QStringList()<< "fff"<<"rrr""1111\n");
                     sk_itm->setCheckState(0,Qt::Unchecked);
                     QTreeWidgetItem *b_itm=new QTreeWidgetItem(itm, QStringList()<< "ggg"<<"eee"<<"1111");
                     b_itm->setCheckState(0,Qt::Unchecked);
                     QTreeWidgetItem *j_itm=new QTreeWidgetItem(itm, QStringList()<< "hhh"<<"eee"<<"1111 \n");
                     j_itm->setCheckState(0,Qt::Unchecked);
                     QTreeWidgetItem *h_itm=new QTreeWidgetItem(itm,QStringList() <<"iii"<<"yyy"<<"1111 \n");
                     h_itm->setCheckState(0,Qt::Unchecked);
                     new QTreeWidgetItem(itm,QStringList() <<"jjj"<<"xxx"<<"1111 \n");
                  
                  
                     QTreeWidgetItem *qqq = new QTreeWidgetItem(*k_itm,QStringList() <<"qqq"<<"qwqe"<<"1111");
                       qqq->setCheckState(0,Qt::Unchecked);
                  
                      QTreeWidgetItem *www =new QTreeWidgetItem(s_itm,QStringList() <<"www"<<"nun"<<"1111");
                      www->setCheckState(0,Qt::Unchecked);
                  
                      QTreeWidgetItem *eee= new QTreeWidgetItem(e_itm,QStringList() <<"eee"<<"vvv"<<"1111");
                      eee->setCheckState(0,Qt::Unchecked);
                  
                  
                  
                      QTreeWidgetItem *nnn = new QTreeWidgetItem(e_itm,QStringList() <<"nnn"<<"nhn"<<"1111");
                      nnn->setCheckState(0,Qt::Unchecked);
                  
                      QTreeWidgetItem *pop = new QTreeWidgetItem(y_itm,QStringList() <<"pop"<<"fff"<<"1111 ");
                      pop->setCheckState(0,Qt::Unchecked);
                  
                     QTreeWidgetItem *zaz = new QTreeWidgetItem(sk_itm,QStringList() <<"zaz"<<"fgf"<<"1111");
                     zaz->setCheckState(0,Qt::Unchecked);
                  
                     QTreeWidgetItem *xsxs = new QTreeWidgetItem(b_itm,QStringList() <<"xsxs"<<"yhgf"<<"1111 ");
                     xsxs->setCheckState(0,Qt::Unchecked);
                  
                     QTreeWidgetItem *cdcd = new QTreeWidgetItem(j_itm,QStringList() <<"cdcd"<<"poj"<<"1111");
                     cdcd->setCheckState(0,Qt::Unchecked);
                  
                      QTreeWidgetItem *vfvf = new QTreeWidgetItem(h_itm,QStringList() <<"vfvf"<<"fvf"<<"1111");
                      vfvf->setCheckState(0,Qt::Unchecked);
                     
                  }
                  Dialog::~Dialog()
                  {
                      delete ui;
                  }
                  
                  void Dialog::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)
                          //  if(item->checkState(0)== Qt::Checked){
                  
                  
                          strTo.append(item->text(0)+";");
                  }
                     // if(item->checkState(0)== Qt::Checked)
                   //   {         ui->treeWidget->;
                  
                   //   }
                          openUrl->openUrl(QUrl(strTo));
                  }
                  
                  I Offline
                  I Offline
                  iqbalfaheem21
                  wrote on last edited by
                  #10

                  @iqbalfaheem21

                  The program is getting crashed when I click the send email button.
                  There should be some solution. I think I am missing some functions. Hope somebody replies soon with the solution.

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

                    sorry, my bad, I had this: for(int j=0;i /* i instead of j*/ <model->columnCount(parent );++j){

                    corrected now

                    "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

                    1 Reply Last reply
                    2
                    • I Offline
                      I Offline
                      iqbalfaheem21
                      wrote on last edited by
                      #12

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

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

                                          • Login

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