Results 1 to 2 of 2

Thread: Connecting 2 different classes together

  1. #1

    Default Connecting 2 different classes together

    Hello, I am trying to send a signal from one class to another class. For this, I am using a connect line such as this:
    Qt Code:
    1. USB *USBInstance = new USB;
    2. connect(this,SIGNAL(sendChosenComPort(QString)),USBInstance,SLOT(receiveChosenComPort()));
    To copy to clipboard, switch view to plain text mode 
    But after I add these lines, when I run, "The program has unexpectedly finished." error appears.
    Then I tried to add

    Qt Code:
    1. USB* USBInstance ;
    To copy to clipboard, switch view to plain text mode 
    to the header file and

    Qt Code:
    1. USBInstance = new USB()
    To copy to clipboard, switch view to plain text mode 
    to cpp. file. But again that gives an error. How can I connect 2 different classes in order to send a signal? Thanks beforehand.
    P.S: I am a total newbie to QT, so please explain it accordingly .

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,658
    Thanks
    13
    Thanked 1,594 Times in 1,522 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Connecting 2 different classes together

    Quote Originally Posted by GunkutA View Post
    But after I add these lines, when I run, "The program has unexpectedly finished." error appears.
    This is usually the result of using a pointer that is not initialised (a run time C++ issue and not a compilation issue). There's not enough of your code here to make the problem obvious.

    If removing both lines removes the problem then a guess would be that the constructor of the USB object is failing.
    If removing only the connect() call removes the problem then my guess is the USBInstance variable here is uninitialised ( probably not the same USBInstance as you created), or the slot is called and does something with an invalid pointer.

    Run your program your in debugger and let it crash. You should be able to see a backtrace leading from the point of failure back into your code. Inspect that back trace and inspect variable involved for clues.
    "We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
    If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.

Similar Threads

  1. Replies: 5
    Last Post: 5th April 2017, 18:33
  2. QFtp not connecting?
    By budda in forum Newbie
    Replies: 1
    Last Post: 9th August 2011, 19:13
  3. How to access Classes from another Classes
    By revellix in forum General Programming
    Replies: 1
    Last Post: 4th August 2011, 15:39
  4. construction of classes within classes
    By mobucl in forum Newbie
    Replies: 8
    Last Post: 10th January 2011, 13:51
  5. Connecting two classes with slgnal and slot
    By Benjamin in forum Newbie
    Replies: 2
    Last Post: 22nd January 2009, 13:16

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.