Since I wanted to have access to the index in another file (code2.cpp), i have written this line in code1.cpp:
Qt Code:
Switch view
connect(mComboBoxSigSelect, SIGNAL(currentIndexChanged(int)), this, SIGNAL(CurrentIndex(int)));
To copy to clipboard, switch view to plain text mode
and mentioned
signals:
int CurrentIndex(int);
in its header so that I can emit the signal from code1.cpp.
Is it not right?
right and should work
but how ur integrating two objects code1 and code2
My_Signals and My_Class how u are calling it.
if ur calling the two classes in a seperate class then
u can do
connect(My_Signals->mComboBoxSigSelect, SIGNAL(currentIndexChanged(int)),My_Class , SLOT(CurrentIndex(int)));
if u r calling M_Signals object in M_Class then
connect(My_Signals->mComboBoxSigSelect, SIGNAL(currentIndexChanged(int)),this , SLOT(CurrentIndex(int)))
is it clear to u ..?
Added after 26 minutes:
signal code
#include <QWidget>
#include <QComboBox>
{
Q_OBJECT
public:
explicit M_Signal
(QWidget *parent
= 0);
signals:
void IndexChanged(int);
public slots:
};
#include <QWidget>
#include <QComboBox>
class M_Signal : public QWidget
{
Q_OBJECT
public:
explicit M_Signal(QWidget *parent = 0);
QComboBox *mComboBoxSigSelect;
signals:
void IndexChanged(int);
public slots:
};
To copy to clipboard, switch view to plain text mode
its cpp
#include "m_signal.h"
M_Signal
::M_Signal(QWidget *parent
) :{
mComboBoxSigSelect->addItem("Hai");
mComboBoxSigSelect->addItem("Hello");
mComboBoxSigSelect->addItem("Way");
mComboBoxSigSelect->addItem("good");
connect(mComboBoxSigSelect, SIGNAL(currentIndexChanged(int)), this, SIGNAL(IndexChanged(int)));
}
#include "m_signal.h"
M_Signal::M_Signal(QWidget *parent) :
QWidget(parent)
{
mComboBoxSigSelect = new QComboBox(this);
mComboBoxSigSelect->addItem("Hai");
mComboBoxSigSelect->addItem("Hello");
mComboBoxSigSelect->addItem("Way");
mComboBoxSigSelect->addItem("good");
connect(mComboBoxSigSelect, SIGNAL(currentIndexChanged(int)), this, SIGNAL(IndexChanged(int)));
}
To copy to clipboard, switch view to plain text mode
M_Class Object
#include "m_signal.h"
{
Q_OBJECT
public:
private slots:
void currentIndexChanged(int);
private:
M_Signal *m_signal;
int mCurrentIndex;
};
#include "m_signal.h"
class M_Class : public QWidget
{
Q_OBJECT
public:
M_Class(QWidget *parent =0);
private slots:
void currentIndexChanged(int);
private:
M_Signal *m_signal;
int mCurrentIndex;
};
To copy to clipboard, switch view to plain text mode
#include "m_class.h"
#include <QDebug>
{
m_signal = new M_Signal(this);
/* 0ne way*/
connect(m_signal->mComboBoxSigSelect, SIGNAL(currentIndexChanged(int)),this , SLOT(currentIndexChanged(int)));
/*Another way */
connect(m_signal, SIGNAL(IndexChanged(int)),this , SLOT(currentIndexChanged(int)));
}
void
M_Class::currentIndexChanged(int index)
{
qDebug()<<"Index value returns:"<<index;
}
#include "m_class.h"
#include <QDebug>
M_Class::M_Class(QWidget *parent) : QWidget(parent)
{
m_signal = new M_Signal(this);
/* 0ne way*/
connect(m_signal->mComboBoxSigSelect, SIGNAL(currentIndexChanged(int)),this , SLOT(currentIndexChanged(int)));
/*Another way */
connect(m_signal, SIGNAL(IndexChanged(int)),this , SLOT(currentIndexChanged(int)));
}
void
M_Class::currentIndexChanged(int index)
{
qDebug()<<"Index value returns:"<<index;
}
To copy to clipboard, switch view to plain text mode
this way im calling M_Signal inside my M_Class
if u want a seperate Object to connect this both say M_MainWindow
then
connect(My_Signals, SIGNAL(IndexChanged(int)),My_Class , SLOT(CurrentIndex(int)));
Bookmarks