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--------------------
#include <QWidget>
#include <qevent.h>
//#include <QLabel>
#include <QPainter>
#include <QImage>
#include <QPaintEvent>
{
private:
protected:
public:
~displayimage();
};
#include <QWidget>
#include <qevent.h>
//#include <QLabel>
#include <QPainter>
#include <QImage>
#include <QPaintEvent>
class displayimage:public QWidget
{
private:
QImage _image;
protected:
virtual void paintEvent(QPaintEvent*);
public:
QString _fileName;
displayimage(QString);
~displayimage();
};
To copy to clipboard, switch view to plain text mode
------------------displayimage.cpp----------------
#include <fstream.h>
#include <iostream.h>
#include <QMessageBox>
#include <QLabel>
#include "displayimage.h"
displayimage
::displayimage(QString fileName
){
_fileName=fileName;
setWindowTitle(tr("Node Explorer"));
}
displayimage::~displayimage()
{
}
{
cout<<"B4 loading"<<endl;
_image.load(_fileName);
paint.drawImage(paint.window(),_image);
}
#include <fstream.h>
#include <iostream.h>
#include <QMessageBox>
#include <QLabel>
#include "displayimage.h"
displayimage::displayimage(QString fileName)
{
_fileName=fileName;
setWindowTitle(tr("Node Explorer"));
}
displayimage::~displayimage()
{
}
void displayimage::paintEvent(QPaintEvent* paintEvent)
{
QPainter paint(this);
cout<<"B4 loading"<<endl;
_image.load(_fileName);
paint.drawImage(paint.window(),_image);
}
To copy to clipboard, switch view to plain text mode
---------------main.cpp-------------------------
#include <QApplication>
#include <iostream.h>
#include "displayimage.h"
#include "testthread.h"
//using namespace std;
displayimage* obj;
int main(int argc, char *argv[])
{
QString fileName
("/scratchbox/Venkanna.jpg");
obj = new displayimage(fileName);
cout<<"B4 show"<<endl;
obj->show();
Test test;
test.start();
int ret = app.exec();
return ret;
}
#include <QApplication>
#include <iostream.h>
#include "displayimage.h"
#include "testthread.h"
//using namespace std;
displayimage* obj;
int main(int argc, char *argv[])
{
QApplication app(argc,argv);
QString fileName("/scratchbox/Venkanna.jpg");
obj = new displayimage(fileName);
cout<<"B4 show"<<endl;
obj->show();
Test test;
test.start();
int ret = app.exec();
return ret;
}
To copy to clipboard, switch view to plain text mode
------------------testthread.h-------------------------
#include<qthread.h>
{
public :
virtual void run();
};
void Test::run()
{
for(int count =0; count<20; count++)
{
sleep(1);
qDebug(" Thread started");
}
}
#include<qthread.h>
class Test: public QThread
{
public :
virtual void run();
};
void Test::run()
{
for(int count =0; count<20; count++)
{
sleep(1);
qDebug(" Thread started");
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks