Results 1 to 4 of 4

Thread: QImage not loading successively.

  1. #1
    Join Date
    Jun 2008
    Posts
    21
    Thanked 1 Time in 1 Post

    Default QImage not loading successively.

    Hi,

    I am loading a image from file using QImage class. After processing some steps, my application will load the image from other file to the same object. Application is exiting by segmentation fault. My Qt version is 4.4. Please provide me the solution if QImage does't handle two successive image loading.

    Regards,
    node_ex.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QImage not loading successively.

    Please provide some code that you suspect that causes the segfault.

  3. #3
    Join Date
    Jun 2008
    Posts
    21
    Thanked 1 Time in 1 Post

    Default Re: QImage not loading successively.

    Hi Wysota,

    Actually i figured out the issue but unable to resolve it. I am launching a thread before exec. This hinders Qimage from loading an image from file.

    Regards,
    node_ex.

    Code :

    -----------------displayimage.h--------------------
    Qt Code:
    1. #include <QWidget>
    2. #include <qevent.h>
    3. //#include <QLabel>
    4. #include <QPainter>
    5. #include <QImage>
    6. #include <QPaintEvent>
    7.  
    8.  
    9. class displayimage:public QWidget
    10. {
    11. private:
    12. QImage _image;
    13.  
    14. protected:
    15. virtual void paintEvent(QPaintEvent*);
    16. public:
    17. QString _fileName;
    18. displayimage(QString);
    19. ~displayimage();
    20.  
    21. };
    To copy to clipboard, switch view to plain text mode 
    ------------------displayimage.cpp----------------
    Qt Code:
    1. #include <fstream.h>
    2. #include <iostream.h>
    3. #include <QMessageBox>
    4. #include <QLabel>
    5. #include "displayimage.h"
    6.  
    7. displayimage::displayimage(QString fileName)
    8. {
    9.  
    10. _fileName=fileName;
    11. setWindowTitle(tr("Node Explorer"));
    12.  
    13.  
    14. }
    15.  
    16. displayimage::~displayimage()
    17. {
    18.  
    19. }
    20.  
    21. void displayimage::paintEvent(QPaintEvent* paintEvent)
    22. {
    23. QPainter paint(this);
    24.  
    25. cout<<"B4 loading"<<endl;
    26. _image.load(_fileName);
    27.  
    28. paint.drawImage(paint.window(),_image);
    29.  
    30. }
    To copy to clipboard, switch view to plain text mode 
    ---------------main.cpp-------------------------
    Qt Code:
    1. #include <QApplication>
    2. #include <iostream.h>
    3. #include "displayimage.h"
    4. #include "testthread.h"
    5. //using namespace std;
    6.  
    7. displayimage* obj;
    8.  
    9.  
    10. int main(int argc, char *argv[])
    11. {
    12. QApplication app(argc,argv);
    13.  
    14. QString fileName("/scratchbox/Venkanna.jpg");
    15.  
    16. obj = new displayimage(fileName);
    17.  
    18. cout<<"B4 show"<<endl;
    19. obj->show();
    20. Test test;
    21. test.start();
    22. int ret = app.exec();
    23. return ret;
    24. }
    To copy to clipboard, switch view to plain text mode 
    ------------------testthread.h-------------------------
    Qt Code:
    1. #include<qthread.h>
    2.  
    3. class Test: public QThread
    4. {
    5. public :
    6. virtual void run();
    7. };
    8.  
    9. void Test::run()
    10. {
    11.  
    12. for(int count =0; count<20; count++)
    13. {
    14. sleep(1);
    15. qDebug(" Thread started");
    16. }
    17. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 21st July 2008 at 15:41. Reason: missing [code] tags

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QImage not loading successively.

    What if you load the file in the constructor and not in the paint event?

Similar Threads

  1. Replies: 12
    Last Post: 7th September 2011, 16:37
  2. QShared
    By sabeesh in forum Qt Programming
    Replies: 11
    Last Post: 11th October 2007, 12:40
  3. Replies: 7
    Last Post: 12th August 2006, 15:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.