PDA

View Full Version : qobject connect questions



VireX
20th May 2007, 00:12
Hey, I have two questions
1)
I have uig.qpbTest (inside a QDesigner h file, uig is a class of namespace of h file, a qpushbutton*), and when i use connect:

connect(uig.qpbTest, SIGNAL(clicked()), this, SLOT(procTest()));

It doesn't work, procTest is never activated. Why can't I connect this object?
procTest() is a private slot and is moc'ed.

2)
When I try to use a private slot inside a function, it won't launch it:
int CMain::Do_one(){
doSomething(1); // doSomething is a PRIVATE SLOT in CMain.
}
It won't work this way, I dont know why.

marcel
20th May 2007, 00:18
Posting the code would have been really useful.

1) Connect often outputs messages to the console( stderr actually ) when something goes wrong. Look and see if you can find something there.
Have you added Q_OBJECT yo your class definition?

2)It really doesn't matter that it is private, especially if you call it within the same class.
Use qDebug in all the problematic places if you can't debug the app properly.

But as I said, without some sources, I can't really tell you much. Otherwise, the code you posted seems OK.

Regards

VireX
20th May 2007, 00:24
1) "this" has Q_OBJECt and objects do work well, its just this single connect that doesn't work. the uig stuff comes from output of a ui file that QDesigner makes, (uic.exe) and so i didnt feel like posting that.
And I just did Ui::uiClass uig;
2) doSomething(); works in a button I have in the Main class... but when I directly access it inthis way without a "connect"... it doesn't activate. I'm not sure what other code i can post, the code i post would be unrelated.

marcel
20th May 2007, 00:43
It makes no sense doSomething not being called, even if it is a slot. A slot is basically a function and is nothing incorrect if you call it manually.
Are you absolutely sure that the function doesn't called at all, or does get called but just doesn't do anything?

Also, it may be CMain:: do_one(). How do you call this?

VireX
20th May 2007, 01:05
Ok i will take a better look you're probably right.

wysota
20th May 2007, 09:04
How do you know the slot doesn't get called?