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. User Input to QtexEdit to extract Matrix elements
Forum Updated to NodeBB v4.3 + New Features

User Input to QtexEdit to extract Matrix elements

Scheduled Pinned Locked Moved General and Desktop
12 Posts 4 Posters 5.0k 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.
  • W Offline
    W Offline
    Warrior4just
    wrote on last edited by
    #3

    Thanks a lot Raven-woks...that was helpful

    what does the bool do inside the .todouble() method, interesting...i suppose i understand it, but i didn't think .todouble() method could take a reference bool argument.

    My issue now, is the fact that i don' t know how to retrieve the data from the 2D Qlist to display them to QtextEdit.

    i just would like to know how to print a 2D Qlist to QtextEdit which takes only strings

    Thanks a lot for your help

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #4

      [quote author="Warrior4just" date="1390409926"]
      what does the bool do inside the .todouble() method, interesting...i suppose i understand it, but i didn't think .todouble() method could take a reference bool argument.
      [/quote]
      In case the string can not be converted to a numeric value the bool is set to false.
      The QString::toDouble() doesn't take a reference bool variable, but an optional pointer variable.

      [quote author="Warrior4just" date="1390409926"]
      My issue now, is the fact that i don' t know how to retrieve the data from the 2D Qlist to display them to QtextEdit.

      i just would like to know how to print a 2D Qlist to QtextEdit which takes only strings
      [/quote]
      Build your string using QString::number() with the values from the list. Also insert "\n" wherever you need it.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • D Offline
        D Offline
        daemon777
        wrote on last edited by
        #5

        For building longer Strings the arg-Method from QString can be quite usefull.
        Something like QString output = QString("%1 \n%2").arg("String 1",someint) is a very fast way to build such a string.

        1 Reply Last reply
        0
        • W Offline
          W Offline
          Warrior4just
          wrote on last edited by
          #6

          Thank you Raven-workx and Deamon777
          Great...
          But if i wanna use QString::number() , i need to build two loops for each index of the list
          How does one select the indices of 2D List matrix (e.g. rows and colums), i know im' probably thinking in terms of scientific programming, but u seem where i'm going , i(m using the Eigen librabry afterwards
          say
          @
          for (int i , i < matrix.row(), i++)
          {
          for (int j , j< matrix.cols(),j++)
          QString qsval= matrix[j][i].QString::number();
          ui->textEdit_7->setPlainText(qsval);
          }
          }
          @

          Thank you for clarifying...

          1 Reply Last reply
          0
          • raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #7

            Beside you are missing some error checks:
            @
            QString text;
            for (int i , i < matrix.row(), i++)
            {
            for (int j , j< matrix.cols(),j++)
            {
            text += QString::number(matrix[j][i]);
            }
            text += "\n";
            }
            ui->textEdit_7->setPlainText(text);
            @

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            0
            • W Offline
              W Offline
              Warrior4just
              wrote on last edited by
              #8

              Raven-workx

              i don't think what i wrote is correct (assuming i fixed the syntax errors), because, matrix is a QList<Qlist<double>> ...so writing matrix.rows() makes no sense..
              How do i access the length of matrix : numbers of rows
              How do i access the width of matrix: number of columns

              Thank you

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #9

                Hi,

                "QList::count()":http://qt-project.org/doc/qt-5/qlist.html#count-2 to get the number of item

                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
                0
                • W Offline
                  W Offline
                  Warrior4just
                  wrote on last edited by
                  #10

                  SGalst

                  but @Qlist@ is 2D list....

                  count would be for rows or cols...and what's for the other

                  thanks bro

                  1 Reply Last reply
                  0
                  • raven-worxR Offline
                    raven-worxR Offline
                    raven-worx
                    Moderators
                    wrote on last edited by
                    #11

                    yes calling count() on the outermost list is for rows. Calling count() on the QList of an row returns the column count. of this row.
                    Actually it's very similar to a multi-dimensional array.

                    You could also avoid the indices at all:
                    @
                    QString text;
                    foreach( QList<double> row, matrix ) //rows
                    {
                    foreach( double colValue, row ) //cols
                    {
                    text += QString::number(colValue);
                    }
                    text += "\n";
                    }
                    ui->textEdit_7->setPlainText(text);
                    @

                    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                    If you have a question please use the forum so others can benefit from the solution in the future

                    1 Reply Last reply
                    0
                    • W Offline
                      W Offline
                      Warrior4just
                      wrote on last edited by
                      #12

                      Thanks a lot raven-worx for your help, worked well

                      there is one little problem , is that i am unable to display Matrix elements of Eigen's Matrix class of the Eigen library for linear algebra , here is what i did when i wanted to solve an example of a linear system.

                      i can't show the numbers in text edits (text edit 5 and 6)

                      @void MainWindow::on_pushButton_5_clicked()
                      {
                      MatrixXd A = MatrixXd::Random(3,3);
                      VectorXd b = VectorXd::Random(3,1);

                      QString text1;
                      QString text2;
                      
                      for (int i; i<=A.rows();i++)
                      {
                          for (int j;j<=A.cols();j++)
                          {
                              text1 += QString::number(A(i,j))+ " ";
                      
                          }
                      
                          text1 += "\n";
                          text2 +=  QString::number(b(i))+ "\n";
                      }
                      
                       ui->textEdit_5->setPlainText(text1);
                       ui->textEdit_6->setPlainText(text2);
                      
                       //    Vector3f x = A.colPivHouseholderQr().solve(b);
                      

                      }@

                      I appreciate it

                      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