Results 1 to 12 of 12

Thread: Problem with Signals and Slots

  1. #1
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Problem with Signals and Slots

    Hi,

    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,

    Kapil

  2. #2
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with Signals and Slots

    Post the code.

  3. #3
    Join Date
    Jan 2006
    Posts
    30
    Thanks
    6

    Default Re: Problem with Signals and Slots

    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

  4. #4
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with Signals and Slots

    Hi,

    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,

    Kapil
    Attached Files Attached Files

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Problem with Signals and Slots

    You have not instantiated your ActionClass.

    add row:
    Qt Code:
    1. act = new ActionClass;
    To copy to clipboard, switch view to plain text mode 

    somewhere in your SigForm...

    No offense but uhh, I think you should study the concept of signals and slots a bit:
    http://doc.trolltech.com/4.1/signalsandslots.html

  6. #6
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with Signals and Slots

    Hi,

    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,

  7. #7
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with Signals and Slots

    hi,

    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,
    Kapil
    Attached Files Attached Files

  8. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Problem with Signals and Slots

    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...

    ...

  9. #9
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with Signals and Slots

    Hi,

    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..
    Kapil

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem with Signals and Slots

    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.
    Attached Files Attached Files

  11. #11
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with Signals and Slots

    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..

    Kapil

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem with Signals and Slots

    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).

Similar Threads

  1. Signals and Slots Problem
    By GenericProdigy in forum Qt Programming
    Replies: 4
    Last Post: 2nd February 2009, 09:06
  2. Problem with signals & slots
    By Palmik in forum Qt Programming
    Replies: 4
    Last Post: 17th January 2009, 22:45
  3. Problem with SpinBox signals and slots
    By ramstormrage in forum Newbie
    Replies: 4
    Last Post: 2nd May 2008, 01:45
  4. Signals And Slots problem
    By ldiamond in forum Newbie
    Replies: 7
    Last Post: 23rd March 2008, 00:11
  5. Memory Problem with SIGNALS and SLOTS
    By ^NyAw^ in forum Qt Programming
    Replies: 1
    Last Post: 19th March 2007, 20:39

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.