You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Friday, June 26th 2009, 1:40am

QObject::connect: No such slot

I'm writing a program using Qt 4.4.3 and I'm using connect in two different places, and in both places it says no such slot.

My .cpp file:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <QtGui>
#include "tictactoe.h"
#include "button.h"
Tictactoe::Tictactoe(QWidget *parent) : QDialog(parent)
{
  signalMapper = new QSignalMapper(this);
  for (int m = 0; m < numButtons; m++) {
	xoButtons[m] = new Button(tr(""));
	connect(xoButtons[m], SIGNAL(clicked()), signalMapper, SLOT(map()));
	signalMapper->setMapping(xoButtons[m], m);
  }
  connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(buttonClicked(int m)));
  newGameButton = new Button(tr("New Game"));
  connect(newGameButton, SIGNAL(clicked()), this, SLOT(newGame()));
  QGridLayout *mainLayout = new QGridLayout;
  mainLayout->setSizeConstraint(QLayout::SetFixedSize);
  mainLayout->addWidget(newGameButton, 0, 1, 1, 3);
  for (int i = 1; i < numButtons; i++) {
	int row = ((9 - i) / 3) + 1;
	int column = (i - 1) % 3;
	mainLayout->addWidget(xoButtons[i], row, column);
  }
  setLayout(mainLayout);
  setWindowTitle(tr("TicTacToe"));
}
void Tictactoe::buttonClicked(int m) {
  xoButtons[m]->setText("X");
}
void Tictactoe::newGame() {
  setWindowTitle(tr("New Game"));
}

And its header

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#ifndef TICTACTOE_H
#define TICTACTOE_H
#include <QDialog>
#include <QtCore/QSignalMapper>
class Button;
class Tictactoe : public QDialog
{
public:
  Tictactoe(QWidget *parent = 0);
private slots:
  void newGame();
  void buttonClicked(int m);
private:
  QSignalMapper *signalMapper;
  enum { numButtons = 10 };
  Button *newGameButton;
  Button *xoButtons[numButtons];
};
#endif


The weird thing is, the project compiles fine, but when run I get these errors:

Object::connect: No such slot QDialog::buttonClicked(int m)
Object::connect: No such slot QDialog::newGame()

What did I do wrong?

2

Friday, June 26th 2009, 2:48am

Object::connect: No such slot QDialog::buttonClicked(int m)
Object::connect: No such slot QDialog::newGame()

The slots you are passing into the connect function do not exist in QDialog. The following slots exist in QDialog:
I hope this helps, if you have any further questions shoot away.

3

Friday, June 26th 2009, 6:44am

Source code

1
2
3
class Tictactoe : public QDialog
{
public:

No Q_OBJECT macro. Add it. Any class derived from QObject must have it.
Fighting fire with fire.
Three can keep a secret if two of them are dead.