June 21, 2011

TobbY TobbY
Lab Rat
208 posts

[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

 Signature 

Gorilla..

11 replies

June 21, 2011

HuXiKa HuXiKa
Lab Rat
83 posts

You want to download an image and diplay it? Or what do you mean under “display an image through url” ?

 Signature 

If you can find faults of spelling in the text above, you can keep them.

June 21, 2011

Andre Andre
Area 51 Engineer
6031 posts

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.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

June 21, 2011

TobbY TobbY
Lab Rat
208 posts

thanks, it is really helpfull.

 Signature 

Gorilla..

June 21, 2011

TobbY TobbY
Lab Rat
208 posts

can anyone give me an example to do that???

 Signature 

Gorilla..

June 21, 2011

HuXiKa HuXiKa
Lab Rat
83 posts

  1. QNetworkAccessManager m_netwManager = new QNetworkAccessManager(this);
  2. connect(m_netwManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(slot_netwManagerFinished(QNetworkReply*)));
  3.  
  4. QUrl url("http://....");
  5. QNetworkRequest request(url);
  6. m_netwManager->get(request);

the slot:

  1. void MainWindow::slot_netwManagerFinished(QNetworkReply *reply)
  2. {
  3.     if (reply->error() != QNetworkReply::NoError) {
  4.         qDebug() << "Error in" << reply->url() << ":" << reply->errorString();
  5.         return;
  6.     }
  7.    
  8.     QByteArray jpegData = reply->readAll();
  9.     QPixmap pixmap;
  10.     pixmap.loadFromData(jpegData);
  11.     label->setPixmap(pixmap); // or whatever your labels name is
  12. }

Took me 20 secs with google to find this [qtforum.org].

 Signature 

If you can find faults of spelling in the text above, you can keep them.

June 21, 2011

Andre Andre
Area 51 Engineer
6031 posts

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.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

June 22, 2011

TobbY TobbY
Lab Rat
208 posts

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+0×19aa): undefined reference to `_imp___ZN21QNetworkAccessManagerC1EP7QObject’
release/mainwindow.o:mainwindow.cpp:(.text+0×1a01): undefined reference to `_imp___ZN15QNetworkRequestC1ERK4QUrl’
release/mainwindow.o:mainwindow.cpp:(.text+0×1a14): undefined reference to `_imp___ZN21QNetworkAccessManager3getERK15QNetworkRequest’
release/mainwindow.o:mainwindow.cpp:(.text+0×1a1d): undefined reference to `_imp___ZN15QNetworkRequestD1Ev’
release/mainwindow.o:mainwindow.cpp:(.text+0×1e60): undefined reference to `_imp___ZN15QNetworkRequestD1Ev’
collect2: ld returned 1 exit status

*
this error occured… is there any library i need to include*

 Signature 

Gorilla..

June 22, 2011

TobbY TobbY
Lab Rat
208 posts

****this is my pro file****

  1. # Add files and directories to ship with the application
  2. # by adapting the examples below.
  3. # file1.source = myfile
  4. # dir1.source = mydir
  5. DEPLOYMENTFOLDERS = # file1 dir1
  6.  
  7. # Avoid auto screen rotation
  8. #DEFINES += ORIENTATIONLOCK
  9.  
  10. # Needs to be defined for Symbian
  11. #DEFINES += NETWORKACCESS
  12. QT+= core gui networks
  13. symbian:TARGET.UID3 = 0xE5E25B16
  14.  
  15. LIBS += C:\QtSDK\mingw\lib\libws2_32.a
  16.  
  17. # If your application uses the Qt Mobility libraries, uncomment
  18. # the following lines and add the respective components to the
  19. # MOBILITY variable.
  20. # CONFIG += mobility
  21. # MOBILITY +=
  22.  
  23. SOURCES += main.cpp mainwindow.cpp \
  24.     soapClient.cpp \
  25.     soapC.cpp \
  26.     stdsoap2.cpp
  27. HEADERS += mainwindow.h \
  28.     soapStub.h \
  29.     soapH.h \
  30.     soapBasicHttpBinding_USCOREIClientServiceProxy.h \
  31.     stdsoap2.h
  32. FORMS += mainwindow.ui
  33.  
  34. # Please do not modify the following two lines. Required for deployment.
  35. include(deployment.pri)
  36. qtcAddDeployment()
  37.  
  38. OTHER_FILES += \
  39.     BasicHttpBinding_USCOREIClientService.nsmap

[EDIT: code formatting, please wrap in @-tags, Volker]

 Signature 

Gorilla..

June 22, 2011

Franzk Franzk
Lab Rat
830 posts

Isn’t the module called network instead of networks?

 Signature 

“Horse sense is the thing a horse has which keeps it from betting on people.”—W.C. Fields

http://www.catb.org/~esr/faqs/smart-questions.html

June 22, 2011

TobbY TobbY
Lab Rat
208 posts

:-) sorry, my mistake

 Signature 

Gorilla..

June 22, 2011

Franzk Franzk
Lab Rat
830 posts

TobbY wrote:
:-) sorry, my mistake
Qt DevNet: If we point at something, it’s bound to be a mistake. :P

 Signature 

“Horse sense is the thing a horse has which keeps it from betting on people.”—W.C. Fields

http://www.catb.org/~esr/faqs/smart-questions.html

 
  ‹‹ QAbstractItemDelegate::paint() : custom Delegate, how to alter the value displayed in cell - Solved      CReating a DLL whcih can export ’n’ number of functions for a client application ››

You must log in to post a reply. Not a member yet? Register here!