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. How to populate values in my Qdialogbox's linedits?
QtWS25 Last Chance

How to populate values in my Qdialogbox's linedits?

Scheduled Pinned Locked Moved Unsolved General and Desktop
c++qt 5.4qdialogqlineeditqmainwindow
6 Posts 5 Posters 860 Views
  • 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.
  • L Offline
    L Offline
    learnist
    wrote on 25 Sept 2020, 02:18 last edited by
    #1

    in my main window, i have a qlistwidget named employee_list and the items in this qlistwidget are like this
    <FIRM-1> name="Anna Ken" age="25" job="QtMaster",
    <FIRM-2> name="Sir Ron" age="50" job="QtSlave"

    so when i click the items in employee_list qlistwidget, a dialogbox shows up with 3 fields name,age,job like this
    c2c67c9c-d2e2-4eb2-b45d-11c831ab3ef0-image.png

    but when this dialog box shows up, i want the fields name,age,job to be populated , like this, How can i achieve this ?

    06cbe3b5-a89f-48ef-9119-ad0a09ec13c1-image.png

    so far i have tried this.

    void MainWindow::on_employee_list_itemDoubleClicked(QListWidgetItem* item)
    {
        QString test = item->text();             // getting the item text
        std::string test_s = test.toStdString();  //converting it to string from Qstring
        string name_part = "";                     //creating a variable in which name will be stored
    
            int name_pos = test_s.find("name=\"");
            for (int i = name_pos + 6; i < test_s.length();i++)
            {
                if (test_s[i] != '\"')
                    name_part += test_s[i];
                else
                    break;                         //extracting name in the item's text, after this the name_part variable value is Sir ron.  // similar code for extarcting age and job.
                
        if (test_s.find("<FIRM-1>") != std::string::npos)   //if item contains text <FIRM-1> then show this dialogue
        {
            GrpComd grpComd;   //creating instance of dialog
            grpComd.exec();    //showing it 
                  
           grpComd.name_lineedit->settext(name_part);  // i tried this to populate name in name_linedit but getting error , access violation reading location
        }
    }
    
    S J 2 Replies Last reply 25 Sept 2020, 03:35
    0
    • L learnist
      25 Sept 2020, 02:18

      in my main window, i have a qlistwidget named employee_list and the items in this qlistwidget are like this
      <FIRM-1> name="Anna Ken" age="25" job="QtMaster",
      <FIRM-2> name="Sir Ron" age="50" job="QtSlave"

      so when i click the items in employee_list qlistwidget, a dialogbox shows up with 3 fields name,age,job like this
      c2c67c9c-d2e2-4eb2-b45d-11c831ab3ef0-image.png

      but when this dialog box shows up, i want the fields name,age,job to be populated , like this, How can i achieve this ?

      06cbe3b5-a89f-48ef-9119-ad0a09ec13c1-image.png

      so far i have tried this.

      void MainWindow::on_employee_list_itemDoubleClicked(QListWidgetItem* item)
      {
          QString test = item->text();             // getting the item text
          std::string test_s = test.toStdString();  //converting it to string from Qstring
          string name_part = "";                     //creating a variable in which name will be stored
      
              int name_pos = test_s.find("name=\"");
              for (int i = name_pos + 6; i < test_s.length();i++)
              {
                  if (test_s[i] != '\"')
                      name_part += test_s[i];
                  else
                      break;                         //extracting name in the item's text, after this the name_part variable value is Sir ron.  // similar code for extarcting age and job.
                  
          if (test_s.find("<FIRM-1>") != std::string::npos)   //if item contains text <FIRM-1> then show this dialogue
          {
              GrpComd grpComd;   //creating instance of dialog
              grpComd.exec();    //showing it 
                    
             grpComd.name_lineedit->settext(name_part);  // i tried this to populate name in name_linedit but getting error , access violation reading location
          }
      }
      
      S Offline
      S Offline
      shashikumar
      wrote on 25 Sept 2020, 03:35 last edited by
      #2

      @learnist Did you check is their any string coming from Item->text(); ?

      L 1 Reply Last reply 25 Sept 2020, 16:41
      1
      • L learnist
        25 Sept 2020, 02:18

        in my main window, i have a qlistwidget named employee_list and the items in this qlistwidget are like this
        <FIRM-1> name="Anna Ken" age="25" job="QtMaster",
        <FIRM-2> name="Sir Ron" age="50" job="QtSlave"

        so when i click the items in employee_list qlistwidget, a dialogbox shows up with 3 fields name,age,job like this
        c2c67c9c-d2e2-4eb2-b45d-11c831ab3ef0-image.png

        but when this dialog box shows up, i want the fields name,age,job to be populated , like this, How can i achieve this ?

        06cbe3b5-a89f-48ef-9119-ad0a09ec13c1-image.png

        so far i have tried this.

        void MainWindow::on_employee_list_itemDoubleClicked(QListWidgetItem* item)
        {
            QString test = item->text();             // getting the item text
            std::string test_s = test.toStdString();  //converting it to string from Qstring
            string name_part = "";                     //creating a variable in which name will be stored
        
                int name_pos = test_s.find("name=\"");
                for (int i = name_pos + 6; i < test_s.length();i++)
                {
                    if (test_s[i] != '\"')
                        name_part += test_s[i];
                    else
                        break;                         //extracting name in the item's text, after this the name_part variable value is Sir ron.  // similar code for extarcting age and job.
                    
            if (test_s.find("<FIRM-1>") != std::string::npos)   //if item contains text <FIRM-1> then show this dialogue
            {
                GrpComd grpComd;   //creating instance of dialog
                grpComd.exec();    //showing it 
                      
               grpComd.name_lineedit->settext(name_part);  // i tried this to populate name in name_linedit but getting error , access violation reading location
            }
        }
        
        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 25 Sept 2020, 05:47 last edited by
        #3

        @learnist Did you actually debug your code to see what happens?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • S shashikumar
          25 Sept 2020, 03:35

          @learnist Did you check is their any string coming from Item->text(); ?

          L Offline
          L Offline
          learnist
          wrote on 25 Sept 2020, 16:41 last edited by
          #4

          @shashikumar Yes, i am getting string, only problem is propulating that into dialog box.

          J 1 Reply Last reply 25 Sept 2020, 17:22
          0
          • L learnist
            25 Sept 2020, 16:41

            @shashikumar Yes, i am getting string, only problem is propulating that into dialog box.

            J Offline
            J Offline
            JonB
            wrote on 25 Sept 2020, 17:22 last edited by JonB
            #5

            @learnist

                    grpComd.exec();    //showing it 
                          
                   grpComd.name_lineedit->settext(name_part);  // i tried this to populate name in name_linedit but getting error , access violation reading location
            

            The second line compiles, does it? With settext ? Your code compiles with the {s & }s you show, right? OK, I see you've done some editing of the code you have to shorten.

            Did you try doing the second line before the first one, if you want to put the text in before you showed the user the modal dialog?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on 25 Sept 2020, 18:10 last edited by
              #6

              Hi,

              exec is a blocking call so basically you modify your dialog content after you dismiss it.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1

              1/6

              25 Sept 2020, 02:18

              • Login

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