Opps, I already got the answer, haha a simple mistake, but just to share, I should use the overloaded constructor of QImage to specify the width, height and format

Qt Code:
  1. QImage image(50,50,QImage::Format_RGB32); // use the overloaded constructor
  2. QRgb value;
  3.  
  4. // a 2d array named arr with size 50 x 50 including its values was declared earlier
  5.  
  6. for (int i=0;i<maxwidth;i++)
  7. {
  8. for (int j=0;j<maxheight;j++)
  9. {
  10. // set the rgb value based on arrs' value
  11. // set them all the same to make em grayscale?
  12. value = qRgb(arr[i][j],arr[i][j],arr[i][j]);
  13. image.setPixel(i,j,value);
  14. }
  15. }
  16.  
  17. image.save("test.jpg",".jpg");
To copy to clipboard, switch view to plain text mode