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

Adding a KPushButton to KDialogButtonBox

Tags: None
(comma "," separated)
User avatar
lin-unix
Registered Member
Posts
34
Karma
0
OS
In KDialogBoxButton::addButton() what is the third argument?

Code: Select all
KPushButton *addButton (const KGuiItem &guiitem, ButtonRole role, QObject *receiver=0, const char *slot=0)


The QObject *receiver=0 part of it.

I'm trying to put in:

Code: Select all
KPushButton *nextButton = addButton(nextGuiItem, AcceptRole, 0, next());


But, I don't know what to put into the third argument.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
The third argument is the object that will have the slot specified in argument 4 invoked upon it. I gather you have a slot called next() in the class you are currently in? If so, try the following:
Code: Select all
KPushButton *nextButton = addButton(nextGuiItem, AcceptRole, this, SLOT(next()));


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
User avatar
lin-unix
Registered Member
Posts
34
Karma
0
OS
The third argument expects a QObject*, but the class that the slot next() is in, is my custom class derived from KDialogButtonBox(), so I get an error about not having a matching function call.

I'm essentially passing in KReminder* const (when I type 'this' into the third argument), but it expects a QObject*. Is there anyway around this?
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
Is the object which is the parent to your KDialogButtonBox a QWidget? Usually this is subclassed as well, so you should be doing the setup there.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
User avatar
lin-unix
Registered Member
Posts
34
Karma
0
OS
No, the parent is not an object at all. I have it setup as:

<main.cpp>
Code: Select all
...
KReminder *mainWindow = new KReminder(0);
//Maybe I should pass 'this' instead of 0?
mainWindow->show();
...


<kreminder.cpp>
Code: Select all
KReminder::KReminder(QWidget *parent) : KDialogButtonBox(parent)
{}


main constructs an instance of KReminder which is subclassed from KDialogButtonBox().
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
I see. KReminder looks like a KDE PIM class, so I suggest you contact the KDE PIM development team for assistance, as they will know how to best use that class. kde-pim@kde.org.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
User avatar
lin-unix
Registered Member
Posts
34
Karma
0
OS
Hmmm, no not a PIM class.

KReminder is what I'm making myself from scratch. I'm making a program that reminds me of appointments (you know, like the other billion programs that do this.) I'm just using this to get my feet wet in KDE programming.

I'll try kde-devel, see what they have to say.
User avatar
lin-unix
Registered Member
Posts
34
Karma
0
OS
I think someone from kde-devel pinned it down to that fact that the error message says I'm trying to pass in a const.

error: no matching function for call to ‘KReminder::addButton(KGuiItem*&, QDialogButtonBox::ButtonRole, KReminder* const, const char*)’

note: candidates are:
<snip> <a Qt version of the addButton function>

KPushButton* KDialogButtonBox::addButton(const KGuiItem&, QDialogButtonBox::ButtonRole, QObject*, const char*)
<snip> <more Qt versions of the addButton function>


As I have not declared my class as const, we have no idea where it is coming from. Any suggestions?
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
It is probable the function you are currently in is declared, either at the Qt or KDE level as const.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
User avatar
lin-unix
Registered Member
Posts
34
Karma
0
OS
What the hell is this?

Code: Select all
&*this


Obvious a bad hack, but this made my code compile. I'm dereferencing a pointer then getting its' memory address? How would this work?

I have a feeling that my program will explode if I try running it. Any ideas why this allows my code to compile?
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
It likely removes the const-ness from the pointer. You can also do this with "const_cast<YourType*>( this );"


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]


Bookmarks



Who is online

Registered users: Bing [Bot], claydoh, Google [Bot], markhm, rblackwell, sethaaaa, Sogou [Bot], Yahoo [Bot]