You are not logged in.

1

Monday, October 11th 2004, 5:33am

Manage KDE Volume From QT

I've been googl'ing for information on how to both set and get volume ( master and pcm ) information from within my QT application. So far I have not found anything useful. I am making a volume control slider, which I want to have it's 0 correlate with KDE's "0" or no volume, and then same with 100% volume level. And of course I want to tie movement of the slider with changes in the volume in KDE.

Any advice?
"To code or not to code, that is the question"

Christian

Beginner

Posts: 26

Location: Karlsruhe, Germany

Occupation: in training

  • Send private message

2

Monday, October 11th 2004, 5:43am

HI,

in my opinion this is only possible with DCOP - a KDE specific feature.
"You shouldn't learn Qt and be a logical thinking person, but learn Qt to become such" (decoding)
"A C++ compiler is not a baby rattle." (Kevin)

Christian

Beginner

Posts: 26

Location: Karlsruhe, Germany

Occupation: in training

  • Send private message

3

Monday, October 11th 2004, 9:09am

Here is a faq about docp:

http://wiki.qtforum.org/wakka.php?wakka=dcop&v=1cn5

Have fun.
"You shouldn't learn Qt and be a logical thinking person, but learn Qt to become such" (decoding)
"A C++ compiler is not a baby rattle." (Kevin)

4

Tuesday, October 12th 2004, 12:26am

Thank you. I found an example yesterday that had me include a few header files to access to the DCOP interface , but when I went to compile my application after including them, it say it could not find them. Hopefully I will find an example that shows how to include the appropriate header files in my application. For now have a qprocess object interfacing with DCOP via the shell command, but I would rather not do that in the future.
"To code or not to code, that is the question"

Christian

Beginner

Posts: 26

Location: Karlsruhe, Germany

Occupation: in training

  • Send private message

5

Tuesday, October 12th 2004, 7:38am

Can you show us your code? Perhaps we find the mistake together...
"You shouldn't learn Qt and be a logical thinking person, but learn Qt to become such" (decoding)
"A C++ compiler is not a baby rattle." (Kevin)

6

Wednesday, October 13th 2004, 3:54am

Well, there isn't any DCOP code in my application yet, as I cannot get it to complile even if simply include the following files ( from this example : http://phil.freehackers.org/kde/kde-techno/kde-techno-2.html )

#include <dcopclient.h>
#include <kapp.h>


I will say it cannot file the files and not compile. Most likely I need to add a KDE specific library path to the make file, but so far, for the 20 or so examples I have read for using DCOP in C++, there hasn't been the slightest hint as to how to do that. I do appreciate your offer of help, but I am so frustrated now that I think I will work on another part of my application until I cool off. Then I will revisit DCOP and hopefully have better luck with finding useful documentation for it on the web.

Thank You,
"To code or not to code, that is the question"

7

Wednesday, October 13th 2004, 4:29am

Ok, I don't give up so easily. I did a "find /usr -name 'dcop*' " and found the header file in /usr/include/kde ( same as $KDEDIR/include/kde ), I added that to my qmake,pro file and reran "qmake" and "make". The app compiles and runs fine. Now I can research how to access kmix through DCOP and hopefully everything works as advertised from here on out. However, I maintain my complaint against the bad documentation on KDE.org and other sites. If you are going to teach something, teach it completely. Advice or hints can be incomplete, but a tutorial should cover everything from start to finish, all in bite-size portions. :)
"To code or not to code, that is the question"

This post has been edited 1 times, last edit by "fortezza" (Oct 13th 2004, 4:30am)


8

Wednesday, October 13th 2004, 6:02am

lol, now I have given up. Even with the include issue resolved, I get errors for the following code:
***code***

Source code

1
2
3
4
5
6
7
8
#include <kapp.h>

int main(int argc, char **argv)
{
 KApplication app(argc, argv, "a", 0 , 0 );
 //DCOPClient *client = kapp->dcopClient();
 return 0;
}



g++ -o dcop main.o -L/usr/lib/qt-3.3/lib -L/usr/X11R6/lib -lqt-mt -lXext -lX11 -lm
main.o(.text+0x51): In function `main':
/home/fortezza/qt3/dcop/main.cpp:5: undefined reference to `KApplication::KApplication[in-charge](int&, char**, QCString const&, bool, bool)'
main.o(.text+0x61):/home/fortezza/qt3/dcop/main.cpp:7: undefined reference to `KApplication::~KApplication [in-charge]()'
collect2: ld returned 1 exit status
make: *** [dcop] Error 1

So, even the simple act of creating a kde application object does not work, even with the correct header files/library paths. Any ideas?
"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

9

Wednesday, October 13th 2004, 8:45pm

Judging from your command line, you seem to miss linker directives at least for libkdecore (-lkdecore)

Better use a qmake .pro file and add
LIBS += -lkdecore -lDCOP

Cheers,
_
Qt/KDE Developer
Debian User

10

Thursday, October 14th 2004, 5:08am

That was it!

You hit the nail on the head. I was able to createt the DCOPClient object and ( with a lot of experimentation ) , figure how to manipulate the master and pcm volume controls via calls such as :

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
    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", "setMasterVolume(int)", data ) ) {
    if ( ! client->send( "kmix", "Mixer0", "setVolume(int,int)", data ) ) {
      cout << "Error setting  volume." << endl ;
    }
 


I posted that here just in case someone who as in the same boat as I searches these forums, it will increase their chance of finding the information they need to resolve it.

Thanks to everyone who assisted me with figuring this out, I am learning quite a bit via the "trial by fire" method. Another good analogy is learning to swim by jumping into the swimming pool, and so on.
"To code or not to code, that is the question"