You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Wednesday, July 16th 2008, 10:48pm

Solved: How to get QTextEdit to display images in Windows?

I have a simple QT program. It creates a QMainWindow, a QTextEdit, and then it is supposed to put an image in the QTextEdit. Here is the program:

----
#include <QtGui>

class MainWindow : public QMainWindow
{
public:
MainWindow();

private:
QTextEdit * ViewArea;
};

MainWindow::MainWindow() : QMainWindow()
{
ViewArea = new QTextEdit();
ViewArea->setReadOnly(true);
setCentralWidget(ViewArea);

ViewArea->insertHtml("<img src=\"ill1.gif\">");
}

int main(int argc, char ** argv)
{
QApplication app(argc, argv);

MainWindow window;
window.resize(640, 480);
window.show();
return app.exec();
}
----

"ill1.gif" is in the current directory. I compile this simple program in Linux with g++ 4.3.1, and it works fine. But when I compile it for Windows, I have problems. The windows version actually works fine under wine, but when I transfer it to my Windows machine, the QTextEdit does not display the image. The image is in the same directory as the executable on the Windows machine. I have also tried replacing "ill1.gif" with the full pathname of the file, and that doesn't work either.

How can I get Windows to display an image in a QTextEdit? Is there anything wrong with the above program?

UPDATE: I just tried the same thing, but with a png instead of a gif, and it worked fine. I would still like to be able load gifs in Qt in Windows.

UPDATE: I figured it out. After finding this thread: http://lists.trolltech.com/qt-interest/2…ead00018-0.html it was easy. Qt requires a special plugin to load gif images, whereas png are built in. I just had to add the directory imageformats to the directory with the Windows executable, and then put the qgif4.dll file into the imageformats directory.

The reason it worked fine in Linux is because this sort of thing is automatic in Linux (my distro provided the proper libraries when I installed qt), and it worked in wine because that is where I originally installed the 100+ MB qt installation executable, back when I first needed to extract QtGui4.dll and QtCore4.dll so that I could compile against them.

This post has been edited 2 times, last edit by "WK1" (Jul 16th 2008, 11:29pm)