View Full Version : Problem with Signals and Slots

10th February 2006, 05:09

I am able to debug the program and get an '.exe' for my "ui" files created by including the "CONFIG += release" in my ".pro" filles.
But whenever I try to create a program in Signals and Slots which uses the QObject, it gives and error and is not able to execute it.
It execute simple GUI oriented program where not much of information exchange takes place.
After 'make' it creates the ".exe" in release but is giving errors after that, i.e. does not run the program.
I thought that the problem is with the program and not the QT but even if i execute the sample programs given or example from the net, it gives the same error and does not execute them. With Signals and Slots i have made a very basic program and am not able to get the output. Please suggest me a solution to it.

Thanking you,


Chicken Blood Machine
10th February 2006, 06:12
Post the code.

10th February 2006, 07:19
It might be moc-ing problem
check if moc_yoursourcefile.cpp are created or not

and post the code with error then only it is easy to solve

10th February 2006, 10:28

The moc_filename.cpp files are being created. All the neede files are being created and also the .exe is created in the release but the moment i try to execute the code it gives the error..

I am attaching the 4 files and 1 ui files in a zip format with this mesg.

What the code does is that i have created my own slot for the action of a button click which will just print some message on the Text Field. Please check what is the mistake and please help me to find out the solution.

Thanking you,


10th February 2006, 11:51
You have not instantiated your ActionClass.

add row:

act = new ActionClass;

somewhere in your SigForm...

No offense but uhh, I think you should study the concept of signals and slots a bit:

15th February 2006, 06:12

I read the document and tried many different approaches.

with the inclusion of the statement, the program started running but there is one more problem.

my slot is not called on the signal button clicked(). in the code for the second button i have created a slot but that is not called.

how do i call that slot. Please tell me.
I have attached the code earlier in the thread.

Thanking you,

15th February 2006, 10:32

i am attaching the modified code.. this still is not working. when i am trying to call the slot on the signal , it is not working. please tell me what can be the error in it. i am stuck in it for some long time now..

thanking you,

15th February 2006, 11:06
1) You don't create an instance of ActionClass anywhere

2) The main window (which would be created in ActionClass constructor if it would ever get called) would have nothing to do with the main window created in main, which is the actual window being shown

3) A signal must be connected to a SLOT. You are trying to connect a signal to a signal where sender and receiver are exatcly the same...


15th February 2006, 11:22

Thanks for replying...

I have called the signal(Button1) to call another signal(Button2) which in return will call the close slot of the MainWindow shown in the sigform.h in connect function.. that was what i wanted to check that is the connect in the ActionClass constructor being called or not....
((Sender and REciever are different and i can connect a signal to another signal also)

Where do i create the instance of the ActionClass.. If i create it in SigForm.h then it would result in the circular dependency... Please tell me where in the code should i create the instance which would enable me to activate the connect function and on click would call the next signal..

what changes should i make in the code which would make my code run..
Please tell me.. This would resolve my doubts regarding the Signals and Slots..

Thanking you..

15th February 2006, 12:08
I have corrected your code a little so that it works. But the design is terrible, you should never do it this way. The proper way is to inherit or own the Ui::MainWindow object in the main window itself and connecting the action from another class (ActionClass) is really bizare. It looks like you don't have much experience with C++, as you had some C++ errors too.

You should really consider doing one or two tutorials on using Ui files in Qt4.

15th February 2006, 12:32
Thanks very much for solving the problem...

Please suggest me few of the links which could help me in getting the idea on using ui files in QT4...

and can u please explain me my mistake.. i understood the code... what should be the right approach while coding ur own Slots for the Button Signals..


15th February 2006, 12:35
Try our links section, there are links (in Qt subsection) to Johan's tutorials on Qt. And also the tutorial and reference present in Qt docs (http://doc.trolltech.com/4.1).