I am trying to create an application where I am trying to integrate opencv and qt.
I managed successfully to convert a cv::Mat to QImage by using the code below:
opencv images are stepped so that each row begins on a multiple of 32bits, this makes memory access faster. If you are using a 3byte/pixel format then unless you have a width that is 1/3 of a multiple of 4 you will have 'spare' memory at the end of each line
The safe way is to copy the image data a row at a time. The opencv mat.ptr(row) returns a pointer to the start of each row and the QImage .scanline(row) member does the same
See How to output this 24 bit image in Qt
edit: Something like
for (int i=0;i