PDA

View Full Version : slot no work in another class



Aronax
10th January 2011, 12:54
I haven't errors but when i build programm, debug write QObject::connect no such slots Myclass ::MyVoid().
what is it?
Thank's for answers!

Zlatomir
10th January 2011, 12:57
Show us some code

My guess is that you either made some mistake when called connect.
or is void MyVoid() declared as public slots: in the definition of Myclass?

wysota
10th January 2011, 13:03
Also make sure your class has the Q_OBJECT macro and qmake is called after adding it.

Aronax
10th January 2011, 13:51
thanks for answers but I declared MyVoid as public slots and my class has the Q_Object macro and sorry that i don't show code because it on other computer and If you need I show code, please wait a moment..

Added after 13 minutes:



#ifndef __MENUONLEFRLIST_H__
#define __MENUONLEFRLIST_H__
#include <QAction>
#include <QMenu>
#include <QDialog>
#include "ui_CatalogView.h"
#include "CatalogViewImpl.h"

class Menu : public QDialog, public Ui::CatalogView
{
Q_OBJECT
public:
void createMenu(const QPoint &p);
private:
void createActions();

QMenu *menu;

QAction *addDirectory;
QAction *Rename;
QAction *Delete;

};

#endif // __MENUONLEFRLIST_H__




#include "menuOnLeftList.h"

void Menu::createActions(){
addDirectory = new QAction("Add directory", this);
connect (addDirectory, SIGNAL(triggered()), this, SLOT(addBranch()));
Rename = new QAction("Rename", this);
//connect();
Delete = new QAction("Delete", this);
//connect();

}

void Menu::createMenu(const QPoint &pos){

createActions();

menu = new QMenu();
menu->addAction(addDirectory);
menu->addAction(Rename);
menu->addAction(Delete);
menu->exec(pos);

}




#ifndef __CATALOGVIEW_H__
#define __CATALOGVIEW_H__
#include <QDialog>
#include <QTreeView>
#include <QMouseEvent>
#include <QObject>
#include <QPoint>
#include "menuOnLeftList.h"
#include "ui_CatalogView.h"

class CatalogViewImpl : public QDialog, public Ui::CatalogView
{
Q_OBJECT

public:
CatalogViewImpl(QWidget * parent = 0);
private slots:
void newFolder();
void addBranch();
void searchT();
void updateCatalog();
void searchClicked();
void newClass();
//void showMenu(const QPoint &p);
};

#endif // __CATALOGVIEW_H__




#include <QMouseEvent>
#include "CatalogViewImpl.h"
#include "ClickHandler.h"
#include <QAbstractItemView>

int i;
QStandardItemModel *model;
QPoint *point;
ClickHandler *listEvHandler;
CatalogViewImpl :: CatalogViewImpl(QWidget * main):QDialog(main)
{
setupUi(this);

model = new QStandardItemModel();
treeView->setHeaderHidden(true);
treeView->setModel(model);
listEvHandler = new ClickHandler();
treeView->installEventFilter(listEvHandler);

connect (listEvHandler, SIGNAL(send_rightButtonClicked(const QPoint&)), this, SLOT(createMenu(const QPoint &)));
...


QObject::connect no such slots CatalogViewImpl::createMenu();

wysota
10th January 2011, 14:13
So what is the exact message you get? With proper class names and all...

Aronax
10th January 2011, 14:34
when i do it in CatalogViewImpl class without created new class all works fine!
Exact message: QObject::connect: No such slot CatalogViewImpl::createMenu(const QPoint &);
QObject::connect: (receiver name: 'CatalogViewImpl')

wysota
10th January 2011, 14:42
What new class? You mean "Menu"? It has nothing to do with your original class so your original class doesn't contain slots defined in the Menu class.

Archimedes
10th January 2011, 14:44
createMenu(const QPoint &) belongs to class Menu and not to class CatalogViewImpl.
And you do this in CatalogViewImpl constructor:

connect (listEvHandler, SIGNAL(send_rightButtonClicked(const QPoint&)), this, SLOT(createMenu(const QPoint &)));

Aronax
10th January 2011, 14:46
As new class I keep in mind Menu class

Yes, but send_right ButtonClicked is separate class too but it's work..

Aronax
11th January 2011, 10:21
Thanks for answers!! I understood my mistake!