Re: KHTMLPart compilation failed
On Thu 19 February 2004 18:52, charalam@lsi.upc.es wrote:
> I want to upgrade a working kde3.14 application to kde3.2, but it
> fails compiling a KHTMLPart object of my view widget. To debug it, I
> have just changed my object with the following code (provided as part
> of an example found at the kde3.2 api reference):
>
> KURL url = "http://www.kde.org";
> KHTMLPart *w = new KHTMLPart();
>
> but it also fails giving me the same output:
>
> myfile.o (.text +0x538)
> myfile.cpp: undefined reference to 'KHTMLPart(int, QWidget *, char
> const *, QObject *, char const *, KHTMLPart::GUIProfile)'
Should you not be using ktrader to request an object that can handle
mimetype text/html and provides a kpart interface? This would give you
a khtmlpart but if, in future there were multiple providers it would
give you whichever is 'best'.
This code should do what you want:
KTrader::OfferList offers = KTrader::self()->query("text/html",
"'KParts/ReadOnlyPart' in
ServiceTypes");
KLibFactory *factory = 0;
// in theory, we only care about the first one.. but let's try all
// offers just in case the first can't be loaded for some reason
KTrader::OfferList::Iterator it(offers.begin());
for( ; it != offers.end(); ++it) {
KService::Ptr ptr = (*it);
// we now know that our offer can handle HTML and is a part.
// since it is a part, it must also have a library... let's try
to
// load that now
factory = KLibLoader::self()->factory( ptr->library() );
if (factory) {
m_html = static_cast<KParts::ReadOnlyPart *>(factory->create(this,
ptr->name(), "KParts::ReadOnlyPart"));
break;
}
}
For reference it can be found at:
http://phil.freehackers.org/kde/kpart-techno/kpart-techno.html
Hope this helps
Reply to: