[SOLVED]display image through http url
-
hello, i was trying to display an image through http url to QButton or QLabel..
but i was not getting any positive result .
pls help.. thanks
-
You want to download an image and diplay it? Or what do you mean under "display an image through url" ?
-
In the widget world, you can not do that directly.
You'll have to download the image using QNetworkAccessManager, and set the resulting image on the label. -
thanks, it is really helpfull.
-
can anyone give me an example to do that???
-
@
QNetworkAccessManager m_netwManager = new QNetworkAccessManager(this);
connect(m_netwManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(slot_netwManagerFinished(QNetworkReply*)));QUrl url("http://....");
QNetworkRequest request(url);
m_netwManager->get(request);
@the slot:
@
void MainWindow::slot_netwManagerFinished(QNetworkReply *reply)
{
if (reply->error() != QNetworkReply::NoError) {
qDebug() << "Error in" << reply->url() << ":" << reply->errorString();
return;
}QByteArray jpegData = reply->readAll(); QPixmap pixmap; pixmap.loadFromData(jpegData); label->setPixmap(pixmap); // or whatever your labels name is
}@
Took me 20 secs with google to find "this":http://www.qtforum.org/article/33674/how-can-i-download-an-image-from-an-http-url.html.
-
While the above is a good outline of what to do, don't forget to add error checking at the appropriate places in this code.
-
release/mainwindow.o:mainwindow.cpp:(.text+0xa1e): undefined reference to
_imp___ZN21QNetworkAccessManagerC1EP7QObject' release/mainwindow.o:mainwindow.cpp:(.text+0xa75): undefined reference to
_imp___ZN15QNetworkRequestC1ERK4QUrl'
release/mainwindow.o:mainwindow.cpp:(.text+0xa88): undefined reference to_imp___ZN21QNetworkAccessManager3getERK15QNetworkRequest' release/mainwindow.o:mainwindow.cpp:(.text+0xa91): undefined reference to
_imp___ZN15QNetworkRequestD1Ev'
release/mainwindow.o:mainwindow.cpp:(.text+0xf1d): undefined reference to_imp___ZN15QNetworkRequestD1Ev' release/mainwindow.o:mainwindow.cpp:(.text+0x19aa): undefined reference to
_imp___ZN21QNetworkAccessManagerC1EP7QObject'
release/mainwindow.o:mainwindow.cpp:(.text+0x1a01): undefined reference to_imp___ZN15QNetworkRequestC1ERK4QUrl' release/mainwindow.o:mainwindow.cpp:(.text+0x1a14): undefined reference to
_imp___ZN21QNetworkAccessManager3getERK15QNetworkRequest'
release/mainwindow.o:mainwindow.cpp:(.text+0x1a1d): undefined reference to_imp___ZN15QNetworkRequestD1Ev' release/mainwindow.o:mainwindow.cpp:(.text+0x1e60): undefined reference to
_imp___ZN15QNetworkRequestD1Ev'
collect2: ld returned 1 exit statusthis error occured... is there any library i need to include*
-
this is my pro file
@
Add files and directories to ship with the application
by adapting the examples below.
file1.source = myfile
dir1.source = mydir
DEPLOYMENTFOLDERS = # file1 dir1
Avoid auto screen rotation
#DEFINES += ORIENTATIONLOCK
Needs to be defined for Symbian
#DEFINES += NETWORKACCESS
QT+= core gui networks
symbian:TARGET.UID3 = 0xE5E25B16LIBS += C:\QtSDK\mingw\lib\libws2_32.a
If your application uses the Qt Mobility libraries, uncomment
the following lines and add the respective components to the
MOBILITY variable.
CONFIG += mobility
MOBILITY +=
SOURCES += main.cpp mainwindow.cpp
soapClient.cpp
soapC.cpp
stdsoap2.cpp
HEADERS += mainwindow.h
soapStub.h
soapH.h
soapBasicHttpBinding_USCOREIClientServiceProxy.h
stdsoap2.h
FORMS += mainwindow.uiPlease do not modify the following two lines. Required for deployment.
include(deployment.pri)
qtcAddDeployment()OTHER_FILES +=
BasicHttpBinding_USCOREIClientService.nsmap
@[EDIT: code formatting, please wrap in @-tags, Volker]
-
Isn't the module called network instead of networks?
-
:-) sorry, my mistake
-
[quote author="TobbY" date="1308721124"]:-) sorry, my mistake[/quote]Qt DevNet: If we point at something, it's bound to be a mistake. :P