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

KDevelop: I fail to build a basic KParts App

Tags: None
(comma "," separated)
seuchato
Registered Member
Posts
4
Karma
0
Hi all
After a couple of years, I am preparing to write software again. It's gonna be a scientific app for room acoustics analysis. So I brushed up my rusty knowledge on C++ and am now looking to get familiar with KDevelop. So, I thought, I' find myself some tutorials and/or examples.

I am trying to follow them on my system, which is as follows:
OpenSUSE Leap 15.3, up to date as of Feb. 23rd 22
Kdevelop from official suse repo, version 5.6.1, KDE Frameworks 5.76.0, Qt 5.12.7 (compiled against 5.12.7), The xcb windowsystem
PC is i5 4790s, 32 GB Ram

One example is this one: https://userbase.kde.org/Build_your_first_KDE_application_on_Kubuntu#3._Create_a_basic_KDE_Application_using_an_existing_template.
3. Create a basic KDE Application using an existing template
KDE C++ KDevelop Template

Now you should be in a position to be able to create a simple KDE application in KDevelop by performing the following in the menu: Project -> New From Template -> Qt -> Graphical -> C++ KDE Framework

This example project should now compile and execute without KDevelop complaining.

You are now up and running! It should also now be possible to use Qt Creator should this be a preferred option.


I did as instructed, but instead of "Project -> New From Template -> Qt -> Graphical -> C++ KDE Framework", I choose "Project -> New From Template -> Qt -> Graphical -> KParts Program". Then I had to give it a name "KPart", selected Git as versioning soft and finished. I had to set up a build directory "/home/users/seuchato/projects/KPart/build", I choose to omit setting other options and clicked on OK. Beuatiful C++ code is generated and displayyed nicely in the code window :-). I was pleased! In the build tab the following messages appeared:

* ECM (required version >= 5.23.0)
* Qt5Gui (required version >= 5.12.7)
* Qt5 (required version >= 5.6.0)
* Gettext
* KF5I18n (required version >= 5.76.0)
* Qt5Widgets (required version >= 5.12.0)
* KF5Parts (required version >= 5.23.0)
* KF5 (required version >= 5.23.0)

-- Configuring done
-- Generating done
-- Build files have been written to: /home/users/seuchato/projects/KPart/build
*** Finished ***


I hit "execute" on top, Kdevelop prompts me to select/edit a start configuration (what is that really for?). I hit on KPart, apply and OK : nothing! So again, but this time I select "KPart" again and click on "src/shel/kpart" , it adds "kpart" and "debug", in the "kpart" there is "program file "KPart/src/shel/kpart". Furthe the action is set to build. Again, I click apply and OK. It compiles and links:

/home/users/seuchato/projects/KPart/build> make -j4 kpart
Scanning dependencies of target kpart_autogen
[ 20%] Automatic MOC for target kpart
[ 20%] Built target kpart_autogen
Scanning dependencies of target kpart
[ 40%] Building CXX object src/shell/CMakeFiles/kpart.dir/kpart_autogen/mocs_compilation.cpp.o
[ 60%] Building CXX object src/shell/CMakeFiles/kpart.dir/kpartshell.cpp.o
[ 80%] Building CXX object src/shell/CMakeFiles/kpart.dir/main.cpp.o
[100%] Linking CXX executable kpart
[100%] Built target kpart
*** Finished ***


then a message pops up: "Could not find KPart part!" (would have loved to add a picture ere, but cannot figure out how to do this using the form editor) I click on OK and an empty window with the name KPart appears. It has all the basic decorations in the title bar, but no specific application menu, dialog elements or whatever other gui elements it should show imho. (again, a picture would be nice to emphasize what I mean). So, what went wrong?

I switch to "~/projects/KPart/build/src/shell" and there is the executable "kpart", I initiate with "./kpart" and get
kf.xmlgui: cannot find .rc file "kpartui.rc" for component "kpart"

on the terminal, the mentioned message dialog "Could not find KPart part!", clicking OK, the empty program window appears again.

Trying to get rid of the dialog I add "#include "kpartpart.h"" in "main.cpp". KDevelop adds (in red) it cannot find that file. So I need to set the include paths correctly. I choose "project/Settings" and a dialog pops up. Under "Language support" I add "/home/users/seuchato/projects/KPart/src/part", I apply and leave with OK.

/home/users/seuchato/projects/KPart/build> make -j4
[ 11%] Automatic MOC for target kpartpart
[ 22%] Automatic MOC for target kpart
[ 22%] Built target kpartpart_autogen
[ 22%] Built target kpart_autogen
Scanning dependencies of target kpartpart
[ 33%] Building CXX object src/shell/CMakeFiles/kpart.dir/main.cpp.o
[ 44%] Building CXX object src/part/CMakeFiles/kpartpart.dir/kpartpart_autogen/mocs_compilation.cpp.o
[ 55%] Building CXX object src/part/CMakeFiles/kpartpart.dir/kpartpart.cpp.o
/home/users/ck/projects/KPart/src/shell/main.cpp:7:10: fatal error: kpartpart.h: No such file or directory
#include "kpartpart.h"
^~~~~~~~~~~~~
compilation terminated.
make[2]: *** [src/shell/CMakeFiles/kpart.dir/build.make:93: src/shell/CMakeFiles/kpart.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:283: src/shell/CMakeFiles/kpart.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 66%] Linking CXX shared module kpartpart.so
[ 66%] Built target kpartpart
make: *** [Makefile:158: all] Error 2
*** Error: Exitcode 2 ***


So it still does not find "kpartpart.h", I alter "kpartpart.h" to "#include "../part/kpartpart.h" and the red warning disappears. I hit build again, no errors. I run the app again, same same but different:

./kpart
kf.xmlgui: cannot find .rc file "kpartui.rc" for component "kpart"
qt.qpa.xcb: QXcbConnection: XCB error: 3 (BadWindow), sequence: 725, resource id: 46878164, major code: 40 (TranslateCoords), minor code: 0


The line starting with "qt.qpa.xcb:" is new.

So, questions:
[*]how can I omit this: kf.xmlgui: cannot find .rc file "kpartui.rc" for component "kpart"
[*]why is "kpartpart.h" not found despite include path set correctly?
[*]how can I omit "qt.qpa.xcb: QXcbConnection: XCB error: 3 (BadWindow), sequence: 725, "
[*]how can I ad/attach files here?

I would be happy to get answers to above questions, chocolate up as a reward :-)
greez
chris
seuchato
Registered Member
Posts
4
Karma
0
Hi
Figured out howto make the KParts App work:
First the "start configuration" needs to be altered: the "Action" has to be "build and install", not only "build"
Then, hitting shift-F9, I got this:
/home/users/seuchato/projects/KPartApp/build> make -j4 install
[ 22%] Automatic MOC for target kpartapppart
[ 22%] Automatic MOC for target kpartapp
[ 22%] Built target kpartapp_autogen
[ 22%] Built target kpartapppart_autogen
[ 66%] Built target kpartapp
[100%] Built target kpartapppart
Install the project...
-- Install configuration: "Debug"
-- Installing: /usr/lib64/qt5/plugins/kpartapppart.so
CMake Error at src/part/cmake_install.cmake:55 (file):
file INSTALL cannot copy file
"/home/users/seuchato/projects/KPartApp/build/src/part/kpartapppart.so" to
"/usr/lib64/qt5/plugins/kpartapppart.so": Permission denied.
Call Stack (most recent call first):
src/cmake_install.cmake:42 (include)
cmake_install.cmake:42 (include)


make: *** [Makefile:103: install] Error 1
*** Error: Exitcode 2 ***


The key is here: " file INSTALL cannot copy file" ... to "/usr/lib64/qt5/plugins/kpartapppart.so": Permission denied.

Checking permissions for /usr/lib64/qt5/plugins:
ls -ld /usr/lib64/qt5/plugins
drwxr-xr-x 1 root root 15510 24. Feb 08:49 /usr/lib64/qt5/plugins


... makes it obvious: ordinary users do not have write permissions to /usr/lib64/qt5/plugins, which I believe is correct. So, in order to test, I copied as root kpartapppart.so to /usr/lib64/qt5/plugins. Now KPartsapp starts and shows the editor as expected. However, that cannot be the way to do this! So, I deleted kpartapppart.so in /usr/lib64/qt5/plugins again and did:
ln -s ../part/kpartapppart.so kpartapppart.so

altered the "start configuration" back to "build" and triggered shift-F9 et voila: now the KPartsApp starts even from within KDevelop!

Greez
chris
grkinho
Registered Member
Posts
2
Karma
1
Hi,

Glad You found the solution. However, I suggest doing one of the following instead:

1. In Your kpartshell.cpp when doing instantiatePlugin, instead of the "kf5/parts/kpartpart" just put "kpartpart". You don't need to do "build and install" when doing this. Only "build" is enough.

2. Add environment variable "KDE_INSTALL_PLUGINDIR" in your config and put your build folder path there.


I suggest the first solution for easier build/debug sessions, but the second one is probably the correct way to do it.

Overall, it's a bad practice to copy or work in /usr/lib even if You are working with Your own libraries.

Hope this cleared things a little.

Kind regards


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Google [Bot], Sogou [Bot], Yahoo [Bot]