You are not logged in.

  • "David Boosalis" started this thread

Posts: 10

Location: Fresno California, USA

  • Send private message

1

Sunday, July 4th 2004, 4:19am

Easy Example on using KParts

While not new to QT, I am very new to KDE. I would like to learn more about KDEParts, as I would like to be able to embed KWord, and KCalc into my application.

KParts seems to be a bit overwhelming. Perhaps it is easier if you use an IDE, but I would prefer to stay with emacs.

Are there any simple KDE programs that use KDE parts and whose source is available.

KParts seems to be very complicated, are they used much by programmers, or are most KDE apps stand alone.


Thank you

-david
QT Developer

f_edemar

Beginner

Posts: 14

Location: Sweden

  • Send private message

2

Sunday, July 4th 2004, 12:10pm

RE: Easy Example on using KParts

You can create a new application with KParts in KDevelop. (Project->New Project->C++->KDE->Application framework (KParts) ).

Here is a tutorial about KParts:
http://developer.kde.org/documentation/t…ng-plugins.html

btw, KCalc isn't a KParts component, but I think KWord is it.

btw2: I found this too: http://developer.kde.org/documentation/b…pment/ch12.html

This post has been edited 2 times, last edit by "f_edemar" (Jul 4th 2004, 7:23pm)


  • "David Boosalis" started this thread

Posts: 10

Location: Fresno California, USA

  • Send private message

3

Sunday, July 4th 2004, 7:16pm

RE: Easy Example on using KParts

Thank you for the reply. I looked at the example in your URL, and it gets me on the way, but by no means is it complete.

I wish there was really some solid up to date instructions and tutorials on how to use kparts, as it is really very compliated, yet there is very little knowledge of it to be found. I think that is why most appplications seem not to use KPARTS, and just write their own widgets and API. This is a pitty, as it probable leads to a lot of code bloat as nothing in KDE gets reused except the basic widgets. Not only that but it leads to an inconsistant user interface for editing a file for example.

If I don't give up on using kparts all together, perhaps one day I can be that person that writes a complete and up to date tutorial on how to use KParts.

Thanks again
-david
QT Developer

anda_skoa

Professional

Posts: 1,273

Location: Graz, Austria

Occupation: Software Developer

  • Send private message

4

Sunday, July 4th 2004, 11:28pm

Try this

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
KService::Ptr ptr = 
    KServiceTypeProfile::preferredService("application/x-kword", "KOfficePart");
    if (ptr)
    {
        KLibFactory* factory = KLibLoader::self()->factory(ptr->library());
        if (factory)
        {
            KParts::ReadWritePart* part = 
                dynamic_cast<KParts::ReadWritePart*>(factory->create(this, ptr->name(), "KParts::ReadWritePart"));
            if (!part)
            {
                KMessageBox::error(this, "Could not create part");
                return;
            }
        }
    }


Actually it will be something more specific than KParts::ReadWritePart, KoDocument should work as well.

Cheers,
_
Qt/KDE Developer
Debian User