Hi,

I am working in a simple QConsole application, and what I want to do now is some matrix operations.

Let me explain on the go:

Outside my main as global variables I have defined two matrices:

Qt Code:
  1. QVector<QVector<int> > A, B;
To copy to clipboard, switch view to plain text mode 

Inside the main, I set the sizes to them using:

Qt Code:
  1. A.resize(10);
  2. B.resize(10);
  3. for(int i=0; i<10; i++)
  4. {
  5. A[i].resize(10);
  6. B[i].resize(10);
  7. }
To copy to clipboard, switch view to plain text mode 

And then I fill the A matrix with random values from 1 to 10.

What I want to do in some point, is to multiply matrix A by some scalar, but I want the result to be stored in matrix B.

So, I wrote the following void function:

Qt Code:
  1. void Multiply(int scalar, int rows, int cols, QVector<QVector<int> > matrix, QVector<QVector<int> > result)
  2. {
  3.  
  4. for(int i=0; i<rows; i++)
  5. {
  6. for(int j=0; j<cols; j++)
  7. {
  8. result[i][j]=scalar*matrix[i][j];
  9. }
  10. }
  11.  
  12. }
To copy to clipboard, switch view to plain text mode 

And then, inside main, I call, for example:

Qt Code:
  1. Multiply(5, 10, 10, A, B);
To copy to clipboard, switch view to plain text mode 

But the function is not working because matrix B ends up with all values to 0.
However, if I debug and print the values of result[i][j] inside my function, it shows the correct values for the operation.

Do you know why is that happening?

I tried the same multiply function using regular C arrays:

Qt Code:
  1. void Multiply(int scalar, int Matrix[10][10], int Result[10][10])
To copy to clipboard, switch view to plain text mode 

And it works well that way...

Can you tell me why my void function is not working properly? Should I try some other way to do the same, since I wanted to do some matrix operations the same way, for example, multiply matrix A with B, and store the result in other matrix C, using some similar void function.

Thanks!