Results 1 to 6 of 6

Thread: Signals- Slots; emit one signal from one Form to multiple forms + mainwindow

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6
    Join Date
    Jan 2019
    Posts
    11
    Thanks
    4
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Signals- Slots; emit one signal from one Form to multiple forms + mainwindow

    Thank you for your contribution,

    Quote Originally Posted by d_stranz View Post
    I agree with Lesiok. You need to show the -complete code- not just the part you think is important.

    My guess is that in every one of the signal / slot connections you are making, you are using a different instance of your "mInterface" class. I say this because in each of the connect() statements, it looks like you are using the address of a member variable (&interface) instead of a pointer. That tells me you are probably creating that variable on the stack during the construction of your forms and are not passing in the address of the single mInterface instance that is the one receiving the data. Only the first instance created does anything, because after it has been bound to the read socket, the other calls to bind() fail (but you don't bother to check to see if the bind() was successful...).
    I think you are right. When I started the program found that the constructor of the class "mInterface" was called 3 times so 3 different instance of mInterface. once by calling the class Mainwindow + once by calling the class Readform and once by calling the class Form2. When i try with pointer by it is the same. I declared a pointer of mInterface in mainwindow, form2 and readForm for signals/slots-connection but nothing else happening only the same result.
    How can i do that(to declare only one instance of mInterface )? can you give me a example?
    thanks.


    Added after 1 8 minutes:


    Quote Originally Posted by d_stranz View Post
    As I guessed:

    class ReadForm has a member variable of type mInterface.
    class Form2 has a member variable of type mInterface.
    class MainWindow has a member variable of type mInterface.

    When constructed, these become three completely independent instances of the mInterface class. Only one of them (whichever is constructed first - probably the one in the MainWindow instance constructed in main.cpp) will be successfully be bound to the socket and receive packets. For the other two, the call to bind() will fail because another instance got there first to bind the socket.

    You need to rethink your design and consider how a single instance of a class can be shared among multiple other class instances. It isn't hard - I gave you a hint in my previous answer.
    it runs very well. Thank you very much for your help.
    Last edited by malone; 24th January 2019 at 21:39.

Similar Threads

  1. Problem with signals slots and emit
    By slqh in forum Newbie
    Replies: 4
    Last Post: 19th September 2011, 09:20
  2. Replies: 1
    Last Post: 21st May 2011, 23:53
  3. Replies: 3
    Last Post: 7th April 2011, 11:09
  4. Emit one signal from multiple classes
    By Ishmael in forum Qt Programming
    Replies: 4
    Last Post: 28th June 2010, 23:57
  5. Connecting slots/signals in subclassed form
    By qball2k5 in forum Qt Programming
    Replies: 2
    Last Post: 7th March 2006, 16:01

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
  •  
Qt is a trademark of The Qt Company.