I have a simple application which has a main window, utilising the designer aspect in Creator. I have a menu item which should open a window with some details I collect from a database. This window and the database management is working OK. The problem I have is actually very simple. I have created a slot in the MainWindow class:
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
public slots:
void showActiveMembers();
private:
Ui::MainWindow *ui;
};
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
public slots:
void showActiveMembers();
private:
Ui::MainWindow *ui;
};
To copy to clipboard, switch view to plain text mode
and in the implementation file I have:
void MainWindow::showActiveMembers()
{
memberWindow *mbrWindow;
mbrWindow = new memberWindow;
mbrWindow->resize(1000,500);
mbrWindow->show();
}
void MainWindow::showActiveMembers()
{
memberWindow *mbrWindow;
mbrWindow = new memberWindow;
mbrWindow->resize(1000,500);
mbrWindow->show();
}
To copy to clipboard, switch view to plain text mode
When I try to create the link to the action_ActiveMembers menu action in the "Signal and Slot Editor", the slot I have created above is not listed in the slots available with MainWindow as the receiving object.
- I recognise that the signature of the slot and signal must match, but looking through the headers, it looks like the signature of the signal is "void triggered()", which matched my signature above.
- I have saved all the files, and in fact built the application with one of the available slots. Under those circumstances it builds OK and runs, but still doesn't recognise my slot.
- I do recognise I can do this in the code, but I am keen to understand why this is not being picked up in Creator.
Have I missed something?
Thanks!
Added after 22 minutes:
Well, I'll reply to my own thread. I am still interested to understand if there is a way of linking the ui signal to a custom slot, but I am now of the opinion that the approach intended is to use the signal/slot editor to link different parts of the ui together, and for custom slots such as mine, it is more appropriate to do the linking in the accompanying code:
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->actionActive_Members,SIGNAL(triggered()),
this,SLOT(showActiveMembers()));
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->actionActive_Members,SIGNAL(triggered()),
this,SLOT(showActiveMembers()));
}
To copy to clipboard, switch view to plain text mode
Do let me know if I have missed something!
edit: fixed the code in the slot
Bookmarks