You are not logged in.

1

Tuesday, October 19th 2004, 5:49am

DCop client within Subclass?

I am tearing my hair out again attempting to use a DCOPclient pointer within my QT application to access kmix's volume settings. I felt pretty confident as I had previously made a stand-alone application for changing the volume just to make sure I know how to do it.

However, while my test application that used the following two line so create a perfectly usable DCOPclient pointer had no problems:

Source code

1
2
    kapp->dcopClient()->registerAs("MonAppliIface");
    DCOPClient *client = kapp->dcopClient();


My main application that includes a class that uses the exact same lines ( and the same includes, and project file options ) compiles fine, but dies with the following error when run:

Source code

1
2
AILURE (KCmdLineArgs):
Application has not called KCmdLineArgs::init(...).


This is very curious as I did not call KCmdLineArgs::init in my practice program, but it worked fine. Hopefully I don't need to reference any KDE objects in my main, as I am trying to encapsulate all of the KDE functionality within the included class, so that eventually I can change that class to a non-kde one without changing the rest of my code.

for a clearer picture
main.cpp -> main widget -> KDE specifi widget( QObject, actually )
driver program Main Window of App Does all the OS/DM specific work


my test app was fairly simple ( and worked !!! ):

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <kapp.h>
#include <dcopclient.h>
#include <dcopobject.h>
#include <qapplication.h>
#include <qstring.h>
#include <iostream.h>
#include <qstring.h>

int main(int argc, char** argv)
{
 if ( argc == 3 ) {  
    QApplication a( argc, argv );
    QByteArray data;
    QDataStream arg( data, IO_WriteOnly );
    bool ok;
    QString strmixer = (QString) argv[1];
    QString strvol = (QString) argv[2];
    int mixer = strmixer.toInt( &ok, 10 );
    int vol = strvol.toInt( &ok, 10 );
    arg << mixer;
    arg << vol;
    kapp->dcopClient()->registerAs("MonAppliIface");
    DCOPClient *client = kapp->dcopClient();
    cout <<  (QString)argv[1] << "\n";
    if ( ! client->send( "kmix", "Mixer0", "setVolume(int,int)", data ) ) {
      cout << "Error setting  volume." << endl; 
    }
 }
 return 0;
}
"To code or not to code, that is the question"

anda_skoa

Professional

Posts: 1,273

Location: Graz, Austria

Occupation: Software Developer

  • Send private message

2

Tuesday, October 19th 2004, 6:50pm

Your test application shouldn't work.
Dereferencing kapp should cause a crash, there is not KApplication instance available, only a QApplication instance.

You could try to link to libDCOP and create the DCOPClient directly.
(Not sure if this relys internally on KDE)

Cheers,
_
Qt/KDE Developer
Debian User

3

Tuesday, October 19th 2004, 8:46pm

I recompiled and re-ran my test DCOP app without changing a single line, it still works to adjust the volume ( I changed the master and the PCM mixer volumes with it ). Perhaps kapp is a static KApplication object? Anyway, I could try linking to the libDCOP, if instructions on how to do so were avaiable. So far I have found no useful hits from Google.com on it.
"To code or not to code, that is the question"

anda_skoa

Professional

Posts: 1,273

Location: Graz, Austria

Occupation: Software Developer

  • Send private message

4

Tuesday, October 19th 2004, 10:46pm

Quoted

Originally posted by fortezza
I recompiled and re-ran my test DCOP app without changing a single line, it still works to adjust the volume ( I changed the master and the PCM mixer volumes with it ). Perhaps kapp is a static KApplication object?

Strange

Quoted


Anyway, I could try linking to the libDCOP, if instructions on how to do so were avaiable.

-lDCOP ?

Try creating a DCOPClient object using

Source code

1
new DCOPClient()


Cheers,
_
Qt/KDE Developer
Debian User

5

Wednesday, October 20th 2004, 3:21am

Oh, I tried that this afternoon ( MST )during my lunch break. (it's really bugging me ). I've tried creating kapplication objects and other techniques in code I have found by searching for "dcop" on the Google search engine., none of them take care of the runtime error I am getting. The only big difference I see between my test dcop application and my project is that in the test all of the work is done in the 'main' function, while in my project it is done in the object's constructor function.

Something I haven't tried as a solution ( because it destroys the encapsulation ), is to create the dcopclient pointer in the 'main' function, and pass it down to the main Widget, and then have the main Widget pass it to the bottom level object that needs it, by adding it as a parameter to that object's constructor.

This seems like a lot work and bad programming for me to manager the Master and PCM mixer objects in Linux ( via kmix ), perhaps there is a nothing way? Originally I did it via QProcess using the dcop binary, but I am REALLY trying to avoid that approach.

Btw, here is the project's make file:

Source code

1
2
3
4
5
6
7
8
TEMPLATE = app
CONFIG -= moc
INCLUDEPATH += . /usr/include/kde
LIBS += -lkdecore -lDCOP

# Input
HEADERS += mediamaster.h mplayer.h 
SOURCES += main.cpp mediamaster.cpp mplayer.cpp 


And I do greatly appreciate the help I have been getting. This type of problem usually has a cause that is staring me in the face, I just have to discern it from the rest of the code. :)
"To code or not to code, that is the question"

anda_skoa

Professional

Posts: 1,273

Location: Graz, Austria

Occupation: Software Developer

  • Send private message

6

Wednesday, October 20th 2004, 5:03am

Quoted

Originally posted by fortezza
This seems like a lot work and bad programming for me to manager the Master and PCM mixer objects in Linux ( via kmix ), perhaps there is a nothing way?

Of course there are other ways, KMix will control the volumne itself (I guess through the sound or mixer API) and it is not even required to run.

Cheers,
_
Qt/KDE Developer
Debian User

7

Thursday, October 21st 2004, 3:55am

Fixed!

Yesterday evening, I acted on the hunch that there was a setting in a file that was not getting updated by my 'make''s or deleted by my 'make clean''s, so I copied just my header and source files over to a new directory, rebuilt the project file, and then recompiled my application. It works perfectly now. I still do not need to create a KApplication objec, but I found I did need to call the DCOPclient::registerAs() function before I could interact with Kmix.

Thank you for your help. I have new issues, but I will save those for another forum post, assuming I cannot figure the answers out on my own.
"To code or not to code, that is the question"