Combining Images sided by side using QPainter and QImage



  • Hi everyone,

    I'm a beginner when it comes to using Qt and I'm having some problems combining two images by using QImage and QPainter. The code I use is below.

    @ QImage image1("C:\Documents and Settings\Macavelly\My Documents\Downloads\images\color\col1.jpg");
    QImage image2("C:\Documents and Settings\Macavelly\My Documents\Downloads\images\color\col2.jpg");
    QImage result(image1.width() + image2.width(), image1.height() ,QImage::Format_RGB32);

    QPainter painter;
    painter.begin(&result);
    painter.drawImage(0, 0, image1);
    painter.drawImage(512, 0, image2);
    painter.end();
    
    result.save("C:\\Documents and Settings\\Macavelly\\My Documents\\Downloads\\images\\color\\com.jpg",0,100);
    

    @

    Image 1 and 2 both are the same width and height. The program compiles but crashes as soon as it launches.

    Thanks in advance for any help.



  • Does it work without QPainter, for example if you replace
    @
    QImage result(image1.width() + image2.width(), image1.height() ,QImage::Format_RGB32);

    QPainter painter;
    painter.begin(&result);
    painter.drawImage(0, 0, image1);
    painter.drawImage(512, 0, image2);
    painter.end();@
    with
    @ QImage result(image1);@



  • Yep it does work without QPainter. From all the checks I did adding QPainter causes the crash. Someone told me they tried the code and it worked for them.

    I guess maybe its my install.

    I installed QT from "http://qt-project.org/downloads" the "Qt 5.0.1 for Windows 32-bit (MinGW 4.7, 823 MB)" version. The error I'm getting in debug is a popup windows saying:

    The inferior stopped because it received a signal from the operating system.
    Signal name: SIGSEGV
    Signal meaning: Segmentation fault

    and the following debug message:

    Debugging starts
    Temporarily disabling breakpoints for unloaded shared library "C:\Qt\Qt5.0.1\5.0.1\mingw47_32\plugins\imageformats\qgifd.dll"
    Temporarily disabling breakpoints for unloaded shared library "C:\Qt\Qt5.0.1\5.0.1\mingw47_32\plugins\imageformats\qicod.dll"
    Temporarily disabling breakpoints for unloaded shared library "C:\Qt\Qt5.0.1\5.0.1\mingw47_32\plugins\imageformats\qjpegd.dll"
    Temporarily disabling breakpoints for unloaded shared library "C:\Qt\Qt5.0.1\5.0.1\mingw47_32\plugins\imageformats\qmngd.dll"
    Temporarily disabling breakpoints for unloaded shared library "C:\Qt\Qt5.0.1\5.0.1\mingw47_32\plugins\imageformats\qsvgd.dll"
    Temporarily disabling breakpoints for unloaded shared library "C:\Qt\Qt5.0.1\5.0.1\mingw47_32\plugins\imageformats\qtgad.dll"
    Temporarily disabling breakpoints for unloaded shared library "C:\Qt\Qt5.0.1\5.0.1\mingw47_32\plugins\imageformats\qtiffd.dll"
    Temporarily disabling breakpoints for unloaded shared library "C:\Qt\Qt5.0.1\5.0.1\mingw47_32\plugins\imageformats\qwbmpd.dll"
    Debugging has finished

    Some googling and it seems it might be a problem with GCC. But I have no clue how to fix it. Anyone has any ideas? My operating systems is Windows XP SP3.



  • @
    My operating systems is Windows XP SP3.
    @
    Thats really, really old... Maybe it would be wise to either upgrade to something more recent or use an older Qt.



  • [quote author="Thomas Zander" date="1361055111"]@
    My operating systems is Windows XP SP3.
    @
    Thats really, really old... Maybe it would be wise to either upgrade to something more recent or use an older Qt.[/quote]
    No. Being "old" can't be an argument for dropping the support for an operating system with 35% market share, sorry.



  • More like 40% for XP



  • So I did a reinstall of QT the same "Qt 5.0.1 for Windows 32-bit (MinGW 4.7, 823 MB)”

    The program still crashes and the same pop up windows still appears with "Segmentation fault" but QT debug now gives this.

    Link to bigger image: http://img577.imageshack.us/img577/742/qpainterhelp.jpg

    !http://img221.imageshack.us/img221/742/qpainterhelp.jpg(qpainter)!



  • So I decided to install the old SDK from http://www.developer.nokia.com/Develop/Qt/Tools/

    "QT SDK 1.2.1"

    And everything works fine. The code runs without a hitch and I get the results I expected.

    I don't know what the problem really is. I'd prefer to work with the latest release but since its not working I can't. Can anyone who installed the “Qt 5.0.1 for Windows 32-bit (MinGW 4.7, 823 MB)” test out the code and let me know if you have any problems with it? I tried the linux version "Qt 5.0.1 for Linux 32-bit (388 MB)" also on Ubuntu 12.10 and it still doesn't work.



  • bq. Being “old” can’t be an argument for dropping the support for an operating system with 35% market share, sorry.

    MS dropped support for it some time ago.
    I think the point is not that support has been dropped, you can still run various 4.8 versions on it and thats got support.

    The point is that if you want the latest and greatest features from Qt, don't expect an OS that was released 11 years ago (with the last bugfix release 6 years ago) to be good-enough.



  • So I installed the same “Qt 5.0.1 for Windows 32-bit (MinGW 4.7, 823 MB)” on a fresh install of Windows 8 and I get the same crash with the same popup as soon as I declare

    painter.begin(&result);

    So I dont think its the Operating system. Can anyone else verify it on their OS with the "Qt 5.0.1 for Windows 32-bit (MinGW 4.7, 823 MB)” install.

    Also uninstalling the “Qt 5.0.1 for Windows 32-bit (MinGW 4.7, 823 MB)” and installing the “QT SDK 1.2.1” it works on Windows 8 but I do get a message saying

    "Qt: untested Windows Version 6.2 Detected!"

    Which isn't a big deal since the code works anyway.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.