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

[SOLVED] currentPath doesn't work using KDE (Using GNOME or Windows it works)

Tags: None
(comma "," separated)
User avatar
Alesete
Registered Member
Posts
12
Karma
0
OS
Hi everyone!

First. I'm new in this forum and I was looking for my problem too much but I didn't found anything, so excuseme if this thread is a repeated thread (sorry).

Second. I'm from Spain, so sorry for my bad english xD.

Ok, the problem is the next. I'm currently developing a Qt application (without kde libs), and the app was compiled and can run in KDE, GNOME and Windows. Everything is ok in GNOME and Windows, but I've a problem with KDE. I have a sub-folder in my project: Folder "Files", with two txt files with some initials configurations. The folder have to be in the same path where the binary is, and everything should works... but in KDE it doesn't.

It is because in Konqueror and Dolphin, when I execute the binary doing double click, they "tell" to the app that the binary is always in my home path (and that's not true) so my app can not read the files in the sub-folder (I use QDir dir = QDir::currentPath()).

I did a simply test: I made the following script:

Code: Select all
#!/bin/bash
pwd >> dir.txt


I gave execute permissions to the script and i did double click on it using dolphin. The result: It creates always a "dir.txt" in my home with the Home Path writed in it. It doesn't matter where the script is, because always do the same... in my home.

I tried the script with Nautilus and Thunar and it works like I want (making a dir.txt in the script's path with that path writed in it). And like I said before my app works fine in GNOME and Windows but not in KDE cause that.

Is that a KDE bug or only a KDE "peculiarity"? is very strange because last year I saw the same with other project.

PD: It occurs in KDE 4 and also in KDE 3. Tested in Suse 11.1, Mandriva 2008.1, and Kubuntu 8.04

Can anyone help me? Should I create a bug issue in the bug tracker and wait?, are there any solution to know where a script/binary is doing double click?

Thank you!!

Last edited by Alesete on Sun May 24, 2009 3:25 pm, edited 1 time in total.
User avatar
beermad
Registered Member
Posts
104
Karma
0
OS
Alesete wrote:Hi everyone!

First. I'm new in this forum and I was looking for my problem too much but I didn't found anything, so excuseme if this thread is a repeated thread (sorry).

Second. I'm from Spain, so sorry for my bad english xD.

It's better than my Spanish:-P

Ok, the problem is the next. I'm currently developing a Qt application (without kde libs), and the app was compiled and can run in KDE, GNOME and Windows. Everything is ok in GNOME and Windows, but I've a problem with KDE. I have a sub-folder in my project: Folder "Files", with two txt files with some initials configurations. The folder have to be in the same path where the binary is, and everything should works... but in KDE it doesn't.

It is because in Konqueror and Dolphin, when I execute the binary doing double click, they "tell" to the app that the binary is always in my home path (and that's not true) so my app can not read the files in the sub-folder (I use QDir dir = QDir::currentPath()).

I did a simply test: I made the following script:

Code: Select all
#!/bin/bash
pwd >> dir.txt


I gave execute permissions to the script and i did double click on it using dolphin. The result: It creates always a "dir.txt" in my home with the Home Path writed in it. It doesn't matter where the script is, because always do the same... in my home.

I tried the script with Nautilus and Thunar and it works like I want (making a dir.txt in the script's path with that path writed in it). And like I said before my app works fine in GNOME and Windows but not in KDE cause that.


Your problem is because Dolphin is "in" your home directory, so the current directory (as found by pwd) is always that.

You can prove this by opening a terminal typing "cd /tmp" and then "dolphin". Double click on your script and it will write "/tmp" as the current directory.
In the settings for the icon you've (I assume) set up for your application (or menu option) you need to set the "Work path" to the directory you want it in. That should then (I think) sort out what you're trying to do.


User avatar
Ignacio Serantes
Registered Member
Posts
453
Karma
1
OS
Is not a good idea trusting in desktop for this stuff. You can try the next few lines and use it in your scripts:

Code: Select all
#!/usr/bin/env bash
BASENAME=`basename "$0"`
DIRNAME=`dirname "$0"`
kdialog --msgbox "Path: $DIRNAMEnName: $BASENAMEnFullpath: $DIRNAME/$BASENAME"


Works even with symlinks :).

I think that with Qt the process will be the same.

Oh, I'm from A Coruña ;).

Yes, I check Qt docs and found something

http://doc.trolltech.com/4.5/qcoreappli ... ionDirPath

Last edited by Ignacio Serantes on Sun May 24, 2009 10:36 pm, edited 1 time in total.


Ignacio Serantes, proud to be a member of KDE forums since 2008-Nov.
User avatar
Alesete
Registered Member
Posts
12
Karma
0
OS
Hi again! Thank you very much for yours responses.

I've solved that by the Ignacio's way. It works now :) thank you!

In my qt code I've changed this:

Code: Select all
QDir dir = QDir::current();


to this:

Code: Select all
QDir dir;
dir.cd(QCoreApplication::applicationDirPath());


And now everything works fine :-D

the script works also, I'll keep it in some secure place for use it in the future :-P


beermad:

You can prove this by opening a terminal typing "cd /tmp" and then "dolphin". Double click on your script and it will write "/tmp" as the current directory.


It still creating "dir.txt" file in the home with the home path writed inside... :-(
But thank you very much for your response :-)



Regards and thank you again guys!


PD: Oh, I'm from Málaga, but I like very much the "Gallegos" people :-D
User avatar
Ignacio Serantes
Registered Member
Posts
453
Karma
1
OS
I forgot quotes in the script and without then if path or file name has spaces the code fails :(.

Code: Select all
#!/usr/bin/env bash
BASENAME=`basename "$0"`
DIRNAME=`dirname "$0"`
kdialog --msgbox "Path: $DIRNAMEnName: $BASENAMEnFullpath: $DIRNAME/$BASENAME"


Ignacio Serantes, proud to be a member of KDE forums since 2008-Nov.


Bookmarks



Who is online

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