[Qt-interest] QPixmap from URL
Scott Aron Bloom
Scott.Bloom at sabgroup.com
Sun Feb 1 19:28:37 CET 2009
FYI.. the reason it probably failed is the format of the data was
probably not set in your load function...
I have used the QByteArray more than once to do this.
Scott
> -----Original Message-----
> From: qt-interest-bounces at trolltech.com [mailto:qt-interest-
> bounces at trolltech.com] On Behalf Of Andreas Diehl
> Sent: 2009-02-01 03:58
> To: qt-interest at trolltech.com
> Subject: Re: [Qt-interest] QPixmap from URL
>
> Hello and thanks for those hints.
> Finally, I managed to read the web address via QHttp and
QTemporaryFile.
> Sadly using QBuffer didn't work although I don't know why, because
data
> from
> QHttp was put into the buffer but loading a pixmap from it didn't do.
>
> Using a temp file did the job and I'm happy with it. Here's my code
> (QtJambi
> 4.4.3):
>
> void loadImage(String imagePath)
> {
> //check for local file
> if ( QFile.exists(imagePath) )
> {
> m_Pixmap = new QPixmap(imagePath);
> return;
> }
>
> //web file
> QUrl imgURL = new QUrl(imagePath);
> m_Http = new QHttp( imgURL.host() );
> m_TempFile = new QTemporaryFile();
> if ( !m_TempFile.open(OpenModeFlag.ReadWrite )
> {
> //error handling
> return;
> }
>
> m_Http.done.connect(this, "slotFinished(boolean)");
> m_Http.get(imgURL.path(), m_TempFile);
> } //void loadImage(String)
>
> void slotFinished(boolean error)
> {
> //some error handling
> m_Pixmap = new QPixmap( m_TempFile.fileName() );
> m_Http.close();
> m_TempFile.close();
> } //void slotFinished(boolean)
>
> I left out some error handling code but the above is all you need and
it
> works at least for my project.
>
> Regards,
> Andreas
>
>
>
> ----- Original Message -----
> From: "Scott Aron Bloom" <Scott.Bloom at sabgroup.com>
> To: <qt-interest at trolltech.com>
> Sent: Saturday, January 31, 2009 7:53 PM
> Subject: Re: [Qt-interest] QPixmap from URL
>
>
> >> From: qt-interest-bounces at trolltech.com [mailto:qt-interest-
> >> bounces at trolltech.com] On Behalf Of Ferenc Stelcz
> >> Sent: Saturday, January 31, 2009 9:31 AM
> >> To: qt-interest at trolltech.com
> >> Subject: Re: [Qt-interest] QPixmap from URL
> >>
> >> Andreas Diehl wrote:
> >> > Hello all.
> >> >
> >> > I've got a QLabel which should display a QPixmap. Loading the
pixmap
> > from a
> >> local path works fine, but using a web address doesn't do. Here's
my
> > code
> >> (using Qt 4.4.3 and QtJambi):
> >> >
> >> Hello Andreas!
> >>
> >> Maybe QPixmap-s can't be constructed from web URLs.
> >> In _theory_ I would try to create a QTemporaryFile, then get the
> >> contents of the image at the URL into it (with QHttp's get()
method)
> >> then pass this temp file to a QPixmap ctor. In theory... :)
> >>
> >> /replied to the wrong address../
> >
> > Correct...
> >
> > You will need to download the information yourself and construct the
> > bitmap...
> >
> > Instead of a temp file.. you could also get it to a QByteArray and
> > construct the the pixmap from there.
> >
> > Scott
> >
> > _______________________________________________
> > Qt-interest mailing list
> > Qt-interest at trolltech.com
> > http://lists.trolltech.com/mailman/listinfo/qt-interest
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list