[Kde-bindings] Help with loading an image from a URL

Chris Gow sniffy at rogers.com
Wed Jun 6 20:25:17 UTC 2007


On Wednesday 06 June 2007 15:47:42 Pau Garcia i Quiles wrote:
> Quoting Chris Gow <sniffy at rogers.com>:
> > On Wednesday 06 June 2007 12:30:42 Pau Garcia i Quiles wrote:
> >> Quoting Chris Gow <sniffy at rogers.com>:
> >> > Ok its working correctly, but is this the correct way to load an image
> >> > from a remote resource or is there an easier way?
> >>
> >> There is an easier way :-)
> >
> > Cool.
> >
> >> You can use KIO. It is explained in Larrosa's KDE tutorial which was
> >> translated to Ruby and is available at
> >> http://developer.kde.org/language-bindings/ruby/kde3tutorial/index.html.
> >>
> >> lthough chapter 11, which is the one dealing with what you want to do,
> >> has not been translated to Ruby yet, it shouldn't be difficult to
> >> understand:
> >> http://developer.kde.org/~larrosa/visualtutorial/chapter11.html
> >
> > I originally looked at the KIO::NetAccess class but dismissed it as  
> > it creates
> > a local file. But given the two options, I guess I'll go with it. Ideally
> > I'd like KIO::NetAccess (or something similar) to take a buffer or
> > something. In any case, I'm having an issue using the KIO::NetAccess
> > class. I can't seem to find the download method locally:
> >
> > irb(main):001:0> require 'korundum'
> > => true
> > irb(main):002:0> tmpFile = ""
> > => ""
> > irb(main):003:0>
> > KIO::NetAccess.download("http://www.google.ca/index.html", tmpFile)
> > NoMethodError: undefined method `download' for KIO::NetAccess:Class
> >         from (irb):3:in `method_missing'
> >         from (irb):3
> >
> > I'm running Kubuntu Feisty w/KDE 3.5.7. According to adept I am using the
> > 3.5.5 bindings.
>
> Two problems here:
> 1) static bool KIO::NetAccess::download(const KURL&, QString&) is  
> KDE_DEPRECATED, so Korundum probably does not allow it (I can't verify  
> because the system I am writing from does not have an usable Korundum  
> installation)
I don't think it does as I tried using a KURL too.
>
> 2) The first argument must be a KURL. Try this:
That's what I saw too, but the p3 tutorial on korundum makes reference to this 
class and it uses a string and the KDeveloper tutorial you mentioned 
originally also uses a string (makes reference to the fact that the C++ 
compiler will figure out what you mean) so I thought that using a string 
would work. Guess not.
>
> require 'korundum'
>
> tmpFile = ""
>
> about = KDE::AboutData.new("test", "Testing KIO", "0.1")
> KDE::CmdLineArgs.init(ARGV, about)
> kapp = KDE::Application.new()
Bingo! I was creating a Qt::Application and not a KDE::Application. I thought 
that since all download needed was a reference to a widget it wouldn't matter 
what the application type was. 

> w = Qt::Widget.new(nil, "mywidget")
> KIO::NetAccess.download(KDE::URL.new("http://www.google.ca/index.html"),  
> tmpFile, w)
>
> You need to create a KDE::Application before you use KIO because it  
> needs a KDE::Instance (at least in KDE 3.x, I think I have read  
> somewhere the need for KInstance's has been reduced on KDE4 but don't  
> trust me on that).
>
> As QtRuby and Korundum are implemented via the wonderful  
> method_missing() method in Ruby, 99% of the time you see a  
> NoMethodError in QtRuby/Korundum it means the parameters you are  
> passing are wrong (wrong class, wrong order, etc).
Yeah I'm finding that out, I'm also learning ruby too so I tried doing 
reflection on the class before posting, but couldn't figure out how to find 
all the methods KIO::NetAccess.methods wasn't returning anything useful.

thanks for all the help

-- chris




More information about the Kde-bindings mailing list