Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Learning
  3. Qt in Education
  4. [SOLVED] Connecting two subclassed widgets using signal/slots
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Connecting two subclassed widgets using signal/slots

Scheduled Pinned Locked Moved Qt in Education
4 Posts 2 Posters 1.6k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • MichalM Offline
    MichalM Offline
    Michal
    wrote on last edited by Michal
    #1

    Hi! It may be a silly question but I have been struggling with this for some time...

    I have a MainWindow with 2xQPushButton: button1 and button2. I click on button1 and object from ClassA (QWidget) is created and shown. In newly opened window I have another QPushButton - buttonA. I would like to click on it and emit a signal to MainWindow's button2.

    The general idea is to use connect(buttonA, SIGNAL(emittedSignalFromClassA()), this, SLOT(doSomethingInMainWindow)));
    The question is how to get a pointer to dynamically created obcject to be "visible" in mainwindow??

    I created this example to understand how to solve my problem, my code requires similar solution. I appreciate any of Your help!

    Regards, Michael.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mcosta
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      I suggest to change your approach to the problem; the simplest way to do this is:

      1. Create a signal in your ClassA:
      Q_SIGNALS:
          void buttonClicked();
      
      1. Connect the buttonA clicked() signal to that signal
      connect(buttonA, SIGNAL(clicked()), this, SIGNAL(buttonClicked()));
      
      1. In your MainWindow connect the buttonClicked signal coming from ClassA to your slot
      _classA = new ClassA();
      connect(_classA, SIGNAL(buttonClicked()), this, SLOT(mySlot()));
      _classA->show();
      
      Happy Programming
      

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      1 Reply Last reply
      1
      • MichalM Offline
        MichalM Offline
        Michal
        wrote on last edited by
        #3

        Thank you, connecting 2 signals did the job! I spent hours to make this work...Have a nice day! ;)

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mcosta
          wrote on last edited by SGaist
          #4

          You're welcome

          Happy Programming

          Once your problem is solved don't forget to:

          • Mark the thread as SOLVED using the Topic Tool menu
          • Vote up the answer(s) that helped you to solve the issue

          You can embed images using (http://imgur.com/) or (http://postimage.org/)

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved