1

I have

class MainWindow : public QMainWindow  { 

    Q_OBJECT

  public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

  private slots:
    void getData();

  private:
    Ui::MainWindow *ui;
    Dialog  *second;
};

and

class Dialog: public QDialog  {
   Q_OBJECT

  public:
    explicit Dialog(QWidget *parent = 0); QDialog * dialog;

    QPushButton *pushButton;
    QPushButton *pushButton_2;

};

and I can connect pushbuttons in class Dialog with function getData() in class MainWindow (Dialog is a child of class Mainwindow)

I tried

connect(*second->pushButton, SIGNAL(clicked()), this,
                             SLOT(getData()));

but I got

error: no matching function for call to
‘MainWindow::connect(QPushButton&, const char [11], MainWindow* const, const char [11])’

How do i connect them?

athspk
  • 6,722
  • 7
  • 37
  • 51
kabell
  • 41
  • 3
  • 1
    Please use code blocks for code, not quotations. There's a help box in the editor to help you out. – Mat Sep 09 '12 at 18:51
  • 1
    May be this post will be at your help.. [StackOverflow][1] [1]: http://stackoverflow.com/questions/7180162/qt-no-matching-function-for-call-to-mainwindowconnect – Tharanga Sep 11 '12 at 11:20

1 Answers1

0

if the dialog is child of QMainWindow subclass (as it would be) you should have something like:

MainWindow::MainWindow(...)
{
  ....

  m_dialog = new Dialog(this);// in .h file it is defined as: "Dialog *m_dialog;"
  ....

  connect(m_dialog->pushButton, SIGNAL(clicked()), this,SLOT(getData()));
}

you don't have to write:

  connect(*m_dialog->pushButton, SIGNAL(clicked()), this,SLOT(getData()));

take a look at this qt code:

Counter a, b;
QObject::connect(&a, SIGNAL(valueChanged(int)),
                 &b, SLOT(setValue(int)));

a.setValue(12);     // a.value() == 12, b.value() == 12
b.setValue(48);     // a.value() == 12, b.value() == 48

as you can see you must use pointer and not QObject.

Alberto
  • 718
  • 4
  • 20