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. When returning a qvector, the contents of the qvector are lost.
Forum Updated to NodeBB v4.3 + New Features

When returning a qvector, the contents of the qvector are lost.

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 4 Posters 579 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 Offline
    I Offline
    IknowQT
    wrote on last edited by
    #1
    QVector<QVector<double>> RegressionClass::PolyRegCoeff(QVector<QVector<double>> x, int M, bool varZero)
    {
        int varStart = 0;
        if (varZero) { varStart = 1; }
    
        int rA  = x[0].count();
        int N   = x[0].count();
        QVector<QVector<double>> matSquaredX(N, QVector<double>(M+1-varStart));
    
        /* estimated polynomial regression coefficients 계산 */
        for (int i = 0; i < N; i++)
        {
            for (int j = varStart; j < M + 1; j++)
    			matSquaredX[i][j - varStart] = pow(x[i][0], j);
        }
    
        return matSquaredX;
    }
    

    I have code like this. When I try to return matSquaredX, size is 0.
    In the for statement, the size of matSquaredX was three.

    1 Reply Last reply
    0
    • I IknowQT

      @SGaist

      my mistake. I solved it.
      I have one more question.

      QVector<QVector<double>>*   get_newX() { return m_newX; };
      QVector<QVector<double>>*   get_newY() { return m_newY; };
      
      Pa->get_newX()[i][0] = X[i][0];
      Pa->get_newY()[i][0] = Y[i][0];
      

      c2679 error occurs.
      Is there a way to enter a value by substituting?
      If you don't declare it as a pointer, your code will work normally.

      KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on last edited by KroMignon
      #7

      @IknowQT said in When returning a qvector, the contents of the qvector are lost.:

      QVector<QVector<double>>*   get_newX() { return m_newX; };
      QVector<QVector<double>>*   get_newY() { return m_newY; };
      
      Pa->get_newX()[i][0] = X[i][0];
      Pa->get_newY()[i][0] = Y[i][0];
      

      If I read right your code, Pa->get_newX() and Pa->get_newY() returns a pointer!

      Should be:

      (*Pa->get_newX())[i][0] = X[i][0];
      (*Pa->get_newY())[i][0] = Y[i][0];
      

      But looks ugly to me, I would work with references or add some more helper functions, like setX() / setY()

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

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

        Hi,

        How did you determine that size ?
        Did you check the value of matSquaredX before the return statement ?

        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
        • I Offline
          I Offline
          IknowQT
          wrote on last edited by
          #3

          @SGaist

          my mistake. I solved it.
          I have one more question.

          QVector<QVector<double>>*   get_newX() { return m_newX; };
          QVector<QVector<double>>*   get_newY() { return m_newY; };
          
          Pa->get_newX()[i][0] = X[i][0];
          Pa->get_newY()[i][0] = Y[i][0];
          

          c2679 error occurs.
          Is there a way to enter a value by substituting?
          If you don't declare it as a pointer, your code will work normally.

          jsulmJ KroMignonK 2 Replies Last reply
          0
          • I IknowQT

            @SGaist

            my mistake. I solved it.
            I have one more question.

            QVector<QVector<double>>*   get_newX() { return m_newX; };
            QVector<QVector<double>>*   get_newY() { return m_newY; };
            
            Pa->get_newX()[i][0] = X[i][0];
            Pa->get_newY()[i][0] = Y[i][0];
            

            c2679 error occurs.
            Is there a way to enter a value by substituting?
            If you don't declare it as a pointer, your code will work normally.

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #4

            @IknowQT said in When returning a qvector, the contents of the qvector are lost.:

            c2679

            Can you please post the actual errror message?

            Instead of returning a pointer to a member you can also return a reference.

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

            I 1 Reply Last reply
            0
            • jsulmJ jsulm

              @IknowQT said in When returning a qvector, the contents of the qvector are lost.:

              c2679

              Can you please post the actual errror message?

              Instead of returning a pointer to a member you can also return a reference.

              I Offline
              I Offline
              IknowQT
              wrote on last edited by
              #5

              @jsulm

              error C2679 binary '=': no operator with type 'T' as right operand, or no conversion allowed. MatrixClassLibrary D:\ProgramSrc\POP\MatrixClassLibrary\MatrixClassLibrary.cpp 38

              jsulmJ 1 Reply Last reply
              0
              • I IknowQT

                @jsulm

                error C2679 binary '=': no operator with type 'T' as right operand, or no conversion allowed. MatrixClassLibrary D:\ProgramSrc\POP\MatrixClassLibrary\MatrixClassLibrary.cpp 38

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #6

                @IknowQT What type are X and Y?

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

                1 Reply Last reply
                0
                • I IknowQT

                  @SGaist

                  my mistake. I solved it.
                  I have one more question.

                  QVector<QVector<double>>*   get_newX() { return m_newX; };
                  QVector<QVector<double>>*   get_newY() { return m_newY; };
                  
                  Pa->get_newX()[i][0] = X[i][0];
                  Pa->get_newY()[i][0] = Y[i][0];
                  

                  c2679 error occurs.
                  Is there a way to enter a value by substituting?
                  If you don't declare it as a pointer, your code will work normally.

                  KroMignonK Offline
                  KroMignonK Offline
                  KroMignon
                  wrote on last edited by KroMignon
                  #7

                  @IknowQT said in When returning a qvector, the contents of the qvector are lost.:

                  QVector<QVector<double>>*   get_newX() { return m_newX; };
                  QVector<QVector<double>>*   get_newY() { return m_newY; };
                  
                  Pa->get_newX()[i][0] = X[i][0];
                  Pa->get_newY()[i][0] = Y[i][0];
                  

                  If I read right your code, Pa->get_newX() and Pa->get_newY() returns a pointer!

                  Should be:

                  (*Pa->get_newX())[i][0] = X[i][0];
                  (*Pa->get_newY())[i][0] = Y[i][0];
                  

                  But looks ugly to me, I would work with references or add some more helper functions, like setX() / setY()

                  It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                  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