Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Sending a signal to my mainwindow
Forum Updated to NodeBB v4.3 + New Features

Sending a signal to my mainwindow

Scheduled Pinned Locked Moved General and Desktop
4 Posts 4 Posters 4.9k Views 1 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.
  • K Offline
    K Offline
    kitten
    wrote on last edited by
    #1

    hi to everyone
    i have a mainwindow and a qwidget. i create a qwidget class to in my mainwindow class
    now i want to when a button on qwidget clicked i send a signal to my mainwindow and my mainwindow do a slot i define
    how can i do it?
    can you give me an example?

    www.kitten.mihanblog.com

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Franzk
      wrote on last edited by
      #2

      Let your widget emit a signal when the button is pressed. Let then your main window connect to that signal.

      @CustomWidget::CustomWidget()
      {
      // ...
      connect(someButton, SIGNAL(clicked()), this, SIGNAL(somethingTriggered()));
      }

      MainWindow::MainWindow()
      {
      // ...
      connect(myCustomWidget, SIGNAL(somethingTriggered()), this, SLOT(doSomethingUseful()));
      }@

      "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        Please follow the "tutorial":http://developer.qt.nokia.com/wiki/Basic_Qt_Programming_Tutorial on the Wiki on this.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          maxim.prishchepa
          wrote on last edited by
          #4

          @MyMainWindow(){
          MyWidget * wdgt = new MyWidget(this);
          connect(wdgt, SIGNAL(mySignal()), this, SLOT(onComeSignal()));
          }

          class MyWidget : public QWidget{ Q_OBJECT
          public: MyWidget(QWidget * parent): QWidget(parent){
          QPushButton * btn = new QPushButton(this);
          connect(btn, SIGNAL(clicked (bool), this, SLOT(onClick(bool)));
          }
          private slots: onClick(bool){emit mySignal();}
          signals: void mySignal();
          }@

          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz).

          1 Reply Last reply
          1

          • Login

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