PDA

View Full Version : No Such Slot



Geoffry31
13th November 2012, 20:49
I'm trying to implement a QT gui in visual studio, and i've been stuck at this point for a few hours and googling hasn't helped me much. It might be worth adding that i'm only using moc and uic, this isn't made as a QT project.

I have my MainMenu.ui which uic's to ui_MainMenu.h
I have MainMenu.h which moc's to moc_MainMenu.cpp
And I have MainMenu.cpp which contains the methods for the slots.

This all compiles, however at runtime i receive the errors

Object::connect: No such slot QMainWindow::menuBarTriggered(QAction*) in c:\......\src\common\ui_mainmenu.h:144
Object::connect: (sender name: 'menubar')
Object::connect: (receiver name: 'MainMenu')
for every one of my slots.

The relevant files are
MainMenu.h

#ifndef MAINMENU_H
#define MAINMENU_H


#include <QtCore/QObject>
#include <QObject>
#include <QtGui/QMainWindow>
#include "ui_MainMenu.h"


namespace Ui
{
class MainMenu;
}

class MainMenu : public QMainWindow
{
Q_OBJECT

public:
MainMenu(QWidget *parent =0);
~MainMenu();

public slots:
void runButtonClicked();
void browseButtonClicked();
void arRadioToggled();
void p2iRadioToggled();
void vfRadioToggled();
void menuBarTriggered(QAction*);

private:
Ui::MainMenu *ui;
};
#endif

MainMenu.cpp

#include "MainMenu.h"
#include "ui_MainMenu.h"
#include "moc_MainMenu.cpp"
#include <iostream>

MainMenu::MainMenu(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainMenu)
{
ui->setupUi(this);
}

MainMenu::~MainMenu()
{
delete ui;
}

void MainMenu::runButtonClicked()
{
std::cout << "run";
}
void MainMenu::browseButtonClicked()
{
std::cout << "browse";
}
void MainMenu::arRadioToggled()
{
std::cout << "ar";
}
void MainMenu::p2iRadioToggled()
{
std::cout << "p2i";
}
void MainMenu::vfRadioToggled()
{
std::cout << "browse";
}
void MainMenu::menuBarTriggered(QAction* a)
{
std::cout << "menu";
}


If you need the moc output or other files i can post those to.

Thanks

amleto
13th November 2012, 21:16
is menuBarTriggered mentioned anywhere in moc_MainMenu.cpp ?

edit:
Also, look at the error message - that slot DOES NOT exist on QMainWindow. It is (supposedly) on YOUR *MainMenu* class

Geoffry31
13th November 2012, 21:18
Appear to be on lines 48 and 62
moc_MainMenu.cpp;


/************************************************** **************************
** Meta object code from reading C++ file 'MainMenu.h'
**
** Created: Tue 13. Nov 20:29:46 2012
** by: The Qt Meta Object Compiler version 63 (Qt 4.8.3)
**
** WARNING! All changes made in this file will be lost!
************************************************** ***************************/

#include "MainMenu.h"
#if !defined(Q_MOC_OUTPUT_REVISION)
#error "The header file 'MainMenu.h' doesn't include <QObject>."
#elif Q_MOC_OUTPUT_REVISION != 63
#error "This file was generated using the moc from 4.8.3. It"
#error "cannot be used with the include files from this version of Qt."
#error "(The moc has changed too much.)"
#endif

QT_BEGIN_MOC_NAMESPACE
static const uint qt_meta_data_MainMenu[] = {

// content:
6, // revision
0, // classname
0, 0, // classinfo
6, 14, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
0, // flags
0, // signalCount

// slots: signature, parameters, type, tag, flags
10, 9, 9, 9, 0x0a,
29, 9, 9, 9, 0x0a,
51, 9, 9, 9, 0x0a,
68, 9, 9, 9, 0x0a,
86, 9, 9, 9, 0x0a,
103, 9, 9, 9, 0x0a,

0 // eod
};

static const char qt_meta_stringdata_MainMenu[] = {
"MainMenu\0\0runButtonClicked()\0"
"browseButtonClicked()\0arRadioToggled()\0"
"p2iRadioToggled()\0vfRadioToggled()\0"
"menuBarTriggered(QAction*)\0"
};

void MainMenu::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
{
if (_c == QMetaObject::InvokeMetaMethod) {
Q_ASSERT(staticMetaObject.cast(_o));
MainMenu *_t = static_cast<MainMenu *>(_o);
switch (_id) {
case 0: _t->runButtonClicked(); break;
case 1: _t->browseButtonClicked(); break;
case 2: _t->arRadioToggled(); break;
case 3: _t->p2iRadioToggled(); break;
case 4: _t->vfRadioToggled(); break;
case 5: _t->menuBarTriggered((*reinterpret_cast< QAction*(*)>(_a[1]))); break;
default: ;
}
}
}

const QMetaObjectExtraData MainMenu::staticMetaObjectExtraData = {
0, qt_static_metacall
};

const QMetaObject MainMenu::staticMetaObject = {
{ &QMainWindow::staticMetaObject, qt_meta_stringdata_MainMenu,
qt_meta_data_MainMenu, &staticMetaObjectExtraData }
};

#ifdef Q_NO_DATA_RELOCATION
const QMetaObject &MainMenu::getStaticMetaObject() { return staticMetaObject; }
#endif //Q_NO_DATA_RELOCATION

const QMetaObject *MainMenu::metaObject() const
{
return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject;
}

void *MainMenu::qt_metacast(const char *_clname)
{
if (!_clname) return 0;
if (!strcmp(_clname, qt_meta_stringdata_MainMenu))
return static_cast<void*>(const_cast< MainMenu*>(this));
return QMainWindow::qt_metacast(_clname);
}

int MainMenu::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
_id = QMainWindow::qt_metacall(_c, _id, _a);
if (_id < 0)
return _id;
if (_c == QMetaObject::InvokeMetaMethod) {
if (_id < 6)
qt_static_metacall(this, _c, _id, _a);
_id -= 6;
}
return _id;
}
QT_END_MOC_NAMESPACE



Also, look at the error message - that slot DOES NOT exist on QMainWindow. It is (supposedly) on YOUR *MainMenu* class
Should I perhaps try changing the MainMenu::<slot> thngies from MainMenu.cpp to QMainWindow? Although MainMenu is an instace of QMainWindow afaik

amleto
13th November 2012, 21:19
please see my added comment.

It might be useful for you to post AT LEAST the connection statement, but preferably you would read my sig ;)

Geoffry31
13th November 2012, 21:25
This is the generated ui_MainMenu.h, line 139+ has the connect statements



/************************************************** ******************************
** Form generated from reading UI file 'MainMenu.ui'
**
** Created: Tue 13. Nov 20:25:08 2012
** by: Qt User Interface Compiler version 4.8.3
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
************************************************** ******************************/

#ifndef UI_MAINMENU_H
#define UI_MAINMENU_H

#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QGroupBox>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
#include <QtGui/QListWidget>
#include <QtGui/QMainWindow>
#include <QtGui/QMenu>
#include <QtGui/QMenuBar>
#include <QtGui/QPlainTextEdit>
#include <QtGui/QPushButton>
#include <QtGui/QRadioButton>
#include <QtGui/QSpinBox>
#include <QtGui/QStatusBar>
#include <QtGui/QWidget>

QT_BEGIN_NAMESPACE

class Ui_MainMenu
{
public:
QAction *actionImport;
QAction *actionExport;
QAction *actionExit;
QWidget *centralwidget;
QGroupBox *navigationGroup;
QRadioButton *arRadio;
QRadioButton *p2iRadio;
QRadioButton *vfRadio;
QGroupBox *mapGroup;
QPushButton *mapBrowseButton;
QListWidget *mapList;
QPushButton *pushButton_2;
QGroupBox *flameGroup;
QSpinBox *iterationsSpin;
QLabel *iterationsLabel;
QGroupBox *cudaGroup;
QPlainTextEdit *cudaText;
QMenuBar *menubar;
QMenu *menuSdf;
QStatusBar *statusbar;

void setupUi(QMainWindow *MainMenu)
{
if (MainMenu->objectName().isEmpty())
MainMenu->setObjectName(QString::fromUtf8("MainMenu"));
MainMenu->resize(396, 416);
actionImport = new QAction(MainMenu);
actionImport->setObjectName(QString::fromUtf8("actionImport"));
actionExport = new QAction(MainMenu);
actionExport->setObjectName(QString::fromUtf8("actionExport"));
actionExit = new QAction(MainMenu);
actionExit->setObjectName(QString::fromUtf8("actionExit"));
centralwidget = new QWidget(MainMenu);
centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
navigationGroup = new QGroupBox(centralwidget);
navigationGroup->setObjectName(QString::fromUtf8("navigationGroup"));
navigationGroup->setGeometry(QRect(200, 5, 186, 91));
navigationGroup->setCheckable(false);
arRadio = new QRadioButton(navigationGroup);
arRadio->setObjectName(QString::fromUtf8("arRadio"));
arRadio->setGeometry(QRect(10, 20, 171, 20));
p2iRadio = new QRadioButton(navigationGroup);
p2iRadio->setObjectName(QString::fromUtf8("p2iRadio"));
p2iRadio->setGeometry(QRect(10, 40, 171, 20));
vfRadio = new QRadioButton(navigationGroup);
vfRadio->setObjectName(QString::fromUtf8("vfRadio"));
vfRadio->setGeometry(QRect(10, 60, 171, 20));
mapGroup = new QGroupBox(centralwidget);
mapGroup->setObjectName(QString::fromUtf8("mapGroup"));
mapGroup->setGeometry(QRect(200, 95, 186, 171));
mapBrowseButton = new QPushButton(mapGroup);
mapBrowseButton->setObjectName(QString::fromUtf8("mapBrowseButton"));
mapBrowseButton->setGeometry(QRect(10, 140, 171, 25));
mapList = new QListWidget(mapGroup);
mapList->setObjectName(QString::fromUtf8("mapList"));
mapList->setGeometry(QRect(10, 20, 171, 111));
mapList->setAcceptDrops(true);
pushButton_2 = new QPushButton(centralwidget);
pushButton_2->setObjectName(QString::fromUtf8("pushButton_2"));
pushButton_2->setGeometry(QRect(250, 310, 75, 23));
flameGroup = new QGroupBox(centralwidget);
flameGroup->setObjectName(QString::fromUtf8("flameGroup"));
flameGroup->setGeometry(QRect(10, 5, 186, 161));
flameGroup->setInputMethodHints(Qt::ImhDigitsOnly);
iterationsSpin = new QSpinBox(flameGroup);
iterationsSpin->setObjectName(QString::fromUtf8("iterationsSpin"));
iterationsSpin->setGeometry(QRect(60, 20, 121, 22));
iterationsSpin->setMaximum(1000000);
iterationsLabel = new QLabel(flameGroup);
iterationsLabel->setObjectName(QString::fromUtf8("iterationsLabel"));
iterationsLabel->setGeometry(QRect(10, 22, 46, 21));
cudaGroup = new QGroupBox(centralwidget);
cudaGroup->setObjectName(QString::fromUtf8("cudaGroup"));
cudaGroup->setGeometry(QRect(10, 165, 186, 211));
cudaText = new QPlainTextEdit(cudaGroup);
cudaText->setObjectName(QString::fromUtf8("cudaText"));
cudaText->setGeometry(QRect(13, 20, 161, 181));
MainMenu->setCentralWidget(centralwidget);
menubar = new QMenuBar(MainMenu);
menubar->setObjectName(QString::fromUtf8("menubar"));
menubar->setGeometry(QRect(0, 0, 396, 21));
menubar->setAcceptDrops(false);
menuSdf = new QMenu(menubar);
menuSdf->setObjectName(QString::fromUtf8("menuSdf"));
MainMenu->setMenuBar(menubar);
statusbar = new QStatusBar(MainMenu);
statusbar->setObjectName(QString::fromUtf8("statusbar"));
MainMenu->setStatusBar(statusbar);
QWidget::setTabOrder(iterationsSpin, cudaText);
QWidget::setTabOrder(cudaText, arRadio);
QWidget::setTabOrder(arRadio, p2iRadio);
QWidget::setTabOrder(p2iRadio, vfRadio);
QWidget::setTabOrder(vfRadio, mapList);
QWidget::setTabOrder(mapList, mapBrowseButton);
QWidget::setTabOrder(mapBrowseButton, pushButton_2);

menubar->addAction(menuSdf->menuAction());
menuSdf->addAction(actionImport);
menuSdf->addAction(actionExport);
menuSdf->addSeparator();
menuSdf->addAction(actionExit);

retranslateUi(MainMenu);
QObject::connect(pushButton_2, SIGNAL(clicked()), MainMenu, SLOT(runButtonClicked()));
QObject::connect(mapBrowseButton, SIGNAL(clicked()), MainMenu, SLOT(browseButtonClicked()));
QObject::connect(arRadio, SIGNAL(toggled(bool)), MainMenu, SLOT(arRadioToggled()));
QObject::connect(p2iRadio, SIGNAL(toggled(bool)), MainMenu, SLOT(p2iRadioToggled()));
QObject::connect(vfRadio, SIGNAL(toggled(bool)), MainMenu, SLOT(vfRadioToggled()));
QObject::connect(menubar, SIGNAL(triggered(QAction*)), MainMenu, SLOT(menuBarTriggered(QAction*)));

QMetaObject::connectSlotsByName(MainMenu);
} // setupUi

void retranslateUi(QMainWindow *MainMenu)
{
MainMenu->setWindowTitle(QApplication::translate("MainMenu", "MainWindow", 0, QApplication::UnicodeUTF8));
actionImport->setText(QApplication::translate("MainMenu", "Import", 0, QApplication::UnicodeUTF8));
actionExport->setText(QApplication::translate("MainMenu", "Export", 0, QApplication::UnicodeUTF8));
actionExit->setText(QApplication::translate("MainMenu", "Exit", 0, QApplication::UnicodeUTF8));
navigationGroup->setTitle(QApplication::translate("MainMenu", "Navigation Technique", 0, QApplication::UnicodeUTF8));
arRadio->setText(QApplication::translate("MainMenu", "Attractor Repeller", 0, QApplication::UnicodeUTF8));
p2iRadio->setText(QApplication::translate("MainMenu", "P2I", 0, QApplication::UnicodeUTF8));
vfRadio->setText(QApplication::translate("MainMenu", "Vector Field", 0, QApplication::UnicodeUTF8));
mapGroup->setTitle(QApplication::translate("MainMenu", "Map", 0, QApplication::UnicodeUTF8));
mapBrowseButton->setText(QApplication::translate("MainMenu", "Browse", 0, QApplication::UnicodeUTF8));
pushButton_2->setText(QApplication::translate("MainMenu", "Run", 0, QApplication::UnicodeUTF8));
flameGroup->setTitle(QApplication::translate("MainMenu", "FLAME GPU Parameters", 0, QApplication::UnicodeUTF8));
iterationsLabel->setText(QApplication::translate("MainMenu", "Iterationsl", 0, QApplication::UnicodeUTF8));
cudaGroup->setTitle(QApplication::translate("MainMenu", "Additional Cuda Parameters", 0, QApplication::UnicodeUTF8));
menuSdf->setTitle(QApplication::translate("MainMenu", "File", 0, QApplication::UnicodeUTF8));
} // retranslateUi

};

namespace Ui {
class MainMenu: public Ui_MainMenu {};
} // namespace Ui

QT_END_NAMESPACE

#endif // UI_MAINMENU_H



Also main.cpp


#include <QtGui/QApplication>
#include "MainMenu.h"

int main( int argc, char** argv)
{
QApplication a(argc, argv);
QMainWindow* w = new QMainWindow();
Ui_MainMenu m;
m.setupUi(w);
w->show();
return a.exec();

}



And i haven't included MainMenu.ui

amleto
13th November 2012, 21:27
Should I perhaps try changing the MainMenu::<slot> thngies from MainMenu.cpp to QMainWindow?
No, that is not your code to modify (at your skill level)


Your problem is that you have got a VARIABLE called MainMenu, that is actually a QMainWindow, and you are trying to treat it like an instance of MainMenu. Oops!

Geoffry31
13th November 2012, 21:39
I have included all 5 files of code now, main.cpp, MainMenu.cpp MainMenu.h moc_MainMenu.cpp and ui_MainMenu.h.
The only other relevant file i havent included is the .ui file as that isn't code.

Added after 9 minutes:


No, that is not your code to modify (at your skill level)


Your problem is that you have got a VARIABLE called MainMenu, that is actually a QMainWindow, and you are trying to treat it like an instance of MainMenu. Oops!
Given that QMainWindow is an already defined QT class, how could i go about resolving this? Should i be using the class Ui_MainMenu instead where ive used MainMenu as a class?

amleto
13th November 2012, 21:42
there are plenty of tutorials and even examples online. There are even examples in the code you already have on your machine.

Geoffry31
13th November 2012, 21:54
Sorted it, the problem was that i was declaring


QMainWindow* w = new QMainWindow();


where it should have been



QMainWindow* w = new MainMenu();


Thanks

My problem was that i was cutting and pasting different tutorials together given all of them use the default name MainWindow.

amleto
13th November 2012, 22:07
cutting and pasting auto-generated code rarely ends well ;)