This forum has been archived. All content is frozen. Please use KDE Discuss instead.

integrate kword in myapp

Tags: None
(comma "," separated)
xyfix
Registered Member
Posts
110
Karma
0

Re: integrate kword in myapp

Fri Jan 15, 2010 3:49 pm
bcooksley,

not sure how to do this. I wanted to try this:
Code: Select all
QCoreApplication* qcapp = QApplication::instance();
QApplication* qapp = dynamic_cast<QApplication*>(qcapp);
MyApp::m_app* app = qobject_cast<MyApp::m_app*>(qapp);
app->m_mainWindow->createGUI(m_part);



But my application has a MyApp class with a protected QApplication member m_app. How will I be able to do the last cast?
Currently I get a:

error: object missing in reference to 'MyApp::m_app'


Anyone got an idea on my "could not find plugin" issue? I'm really stuck on that I would guess it's a simple problem
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

Re: integrate kword in myapp

Fri Jan 15, 2010 9:37 pm
Try this:

Code: Select all
MyApp * app = qobject_cast<MyApp*>( QApplication::instance() );
app->m_mainWindow->createGUI(m_part);


You can do casts from a QCoreApplication object all the way up to your K(Unique)Application subclass without any issues, or interleaving steps


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
xyfix
Registered Member
Posts
110
Karma
0

Re: integrate kword in myapp

Tue Jan 19, 2010 9:47 am
bcooksley,

I've tried this but then an error occured:
Code: Select all
source/Report/preporteditor.cpp: In member function 'void ReportEditor::initialiseReportArea(QWidget*)':
/usr/include/QtCore/qobject.h: In function 'T qobject_cast(QObject*) [with T = MyApp*]':
source/Report/reporteditor.cpp:140:   instantiated from here
/usr/include/QtCore/qobject.h:441: error: 'class MyApp' has no member named 'qt_check_for_QOBJECT_macro'
/usr/include/QtCore/qobject.h:443: error: 'class MyApp' has no member named 'staticMetaObject'


I think that's because MyApp::m_app is a QApplication... :?
My MyApp class .h:
Code: Select all
class MyApp
{
public:
  MyApp( int argc, char* argv[]);
  friend class ReportEditor;
  virtual int run();
 
protected:
  QApplication m_app;
}


and .cpp
Code: Select all
MyApp::MyApp(int argc, char* argv[])
{.....}

MyApp::run()
{
  MainWindow* myMainWindow = new MainWindow();
  m_app.exec();
}
xyfix
Registered Member
Posts
110
Karma
0

Re: integrate kword in myapp  Topic is solved

Wed Jan 20, 2010 10:19 am
OK,

I've created a solution ( perhaps won't win the beauty contest price but it works). I just put my mainwindow in a namespace and created a get function which returns the mainwindow and then ran createGUI()... and it works.
Special thanks to bcooksley, zander,cyrille and the rest of the guys.
dfaure
KDE Developer
Posts
14
Karma
0
OS

Re: integrate kword in myapp

Wed Jan 27, 2010 11:49 am
About the code sample in the initial post: it failed because the plugin is called libkwordpart.so but is located in "modules", which is not what KPluginLoader expects (the compat code for "libfoo in modules" is above KPluginLoader).
=> the solution is KPluginLoader("libkwordpart").

But of course this puts an implementation detail (the name of the module on disk, which should one day be fixed to remove the 'lib' prefix, as one can see in the warnings), so it would be better to start from the desktop file instead, which is less likely to change names. This gives:

Code: Select all
    KService::Ptr service = KService::serviceByDesktopPath("kwordpart.desktop");
    KParts::ReadWritePart *m_part = 0;

    if (service) {
        m_part = service->createInstance<KParts::ReadWritePart>(parent);
        if (m_part) {
            // use m_part->wiget()
            // call m_part->openUrl() so that something is shown.
        } else {
            return 1;
        }
    } else {
        qDebug("service kwordpart.desktop not found");
    }

Last edited by dfaure on Wed Jan 27, 2010 1:12 pm, edited 1 time in total.
xyfix
Registered Member
Posts
110
Karma
0

Re: integrate kword in myapp

Wed Jan 27, 2010 1:02 pm
GREAT!!!! it works perfectly. A HUGE Thanks for dfaure of the kde development team and co-designer of the KParts-technology.
tmoti
Registered Member
Posts
7
Karma
0
OS

Re: integrate kword in myapp

Mon Apr 05, 2010 1:35 pm
I got this working with the KPluginLoader

Code: Select all
KLibFactory *partFactory = KLibLoader::self()->factory("kwordpart");


thank you, xyfix for your help.
xyfix
Registered Member
Posts
110
Karma
0

Re: integrate kword in myapp

Tue Apr 06, 2010 10:07 am
tmoti,

the libloader method is depricated. I had a talk with david faure about it and I changed the kde manual so that it now states that people should use the kservice desktop file instead.


Bookmarks



Who is online

Registered users: bancha, Bing [Bot], Evergrowing, Google [Bot], lockheed, mesutakcan