PDA

View Full Version : signal/slot to add objects ?



rimie23
24th April 2012, 17:42
hi it's me again

i create fuction to add camera if i clic button it add it in positions where is entred its
i make that


page_14 = new QWidget();
page_14->setObjectName(QString::fromUtf8("page_14"));
page_14->setGeometry(QRect(0, 0, 211, 250));


toolBox_5 = new QToolBox(dockWidgetContents_5);
toolBox_5->setObjectName(QString::fromUtf8("toolBox_5"));
toolBox_5->setGeometry(QRect(0, 0, 211, 331));
toolBox_5->setAutoFillBackground(false);
toolBox_5->setFrameShape(QFrame::NoFrame);
toolBox_5->setFrameShadow(QFrame::Plain);
toolBox_5->addItem(page_14, QString::fromUtf8("Object"));
toolBox_5->setItemText(toolBox_5->indexOf(page_14), QApplication::translate("MainWindow", "Camera", 0, QApplication::UnicodeUTF8));

toolButton_17 = new QToolButton(page_13);
toolButton_17->setObjectName(QString::fromUtf8("toolButton_13"));
toolButton_17->setGeometry(QRect(10, 10, 31, 31));
toolButton_17->setText(QApplication::translate("MainWindow", "Add", 0, QApplication::UnicodeUTF8));

doubleSpinBox = new QDoubleSpinBox(groupBox_6);
doubleSpinBox->setObjectName(QString::fromUtf8("doubleSpinBox"));
doubleSpinBox->setGeometry(QRect(10, 40, 51, 22));

doubleSpinBox_2 = new QDoubleSpinBox(groupBox_6);
doubleSpinBox_2->setObjectName(QString::fromUtf8("doubleSpinBox_2"));
doubleSpinBox_2->setGeometry(QRect(70, 40, 51, 22));

doubleSpinBox_3 = new QDoubleSpinBox(groupBox_6);
doubleSpinBox_3->setObjectName(QString::fromUtf8("doubleSpinBox_3"));
doubleSpinBox_3->setGeometry(QRect(130, 40, 51, 22));

label = new QLabel(groupBox_6);
label->setObjectName(QString::fromUtf8("label"));
label->setGeometry(QRect(10, 20, 46, 13));
label->setText(QApplication::translate("MainWindow", "X :", 0, QApplication::UnicodeUTF8));

label_2 = new QLabel(groupBox_6);
label_2->setObjectName(QString::fromUtf8("label_2"));
label_2->setGeometry(QRect(70, 20, 46, 13));
label_2->setText(QApplication::translate("MainWindow", "Y :", 0, QApplication::UnicodeUTF8));

label_3 = new QLabel(groupBox_6);
label_3->setObjectName(QString::fromUtf8("label_3"));
label_3->setGeometry(QRect(130, 20, 46, 13));
label_3->setText(QApplication::translate("MainWindow", "Z :", 0, QApplication::UnicodeUTF8));


my function to add cam is


void OgreWidget::add_camera(const Ogre::Vector3 &pos)
{
char name_cam[16];

sprintf(name_cam, "cam%d", mCount_cam++);

ogreCamera1 = ogreSceneManager->createCamera(std::string(name_cam) +"PlayerCam");

ogreCamera1->setPosition(pos);
ogreCamera1->lookAt(0,0,-200);

}


what i messed ? how i make signal/slot in this case?

AlekseyOk
25th April 2012, 09:03
"signal/slot" for what?!

rimie23
25th April 2012, 10:06
i have like that
7625
want enter X,Y,Z and when i clic add it go to the function add_cam and add the cam in the posiyion X,Y,Z
i must use signal /slot to the button add no?

Le_B
25th April 2012, 10:37
from what you gave, you didn't connect the clicked signal of your button to a slot, so nothing will happen

rimie23
25th April 2012, 10:44
Yes, that's my problem i have problem to edit this signal/slot it's complicate (maybe beacuse i am beginer) so i hope to you help me

viulskiez
25th April 2012, 11:38
Have you read Signals & Slots (http://qt-project.org/doc/qt-4.8/signalsandslots.html) documentation?

rimie23
25th April 2012, 14:14
I read but i still have problem

QObject::connect(pushButton, SIGNAL(clicked()), Form, SLOT(close()));
i want when i clic i add camera that mean i make like that

QObject::connect(add_button, SIGNAL(clicked()), this, SLOT(add_camera()));
?
but how i make signal/slot of the position (add_camera in this position)

Spitfire
25th April 2012, 15:01
You need intermediate slot to capture button click and from that slot emit signal with position constructed from values entered in your spin boxes:


// header
public slots:
void onButtonClicked( void );
void add_camera( const Ogre::Vector3& pos ); // it's just a concept, this slot should be in different class as otherwise there's no point using signals/slots

signals:
void addCameraAt( const Ogre::Vector3& pos );



// connection
connect( buttonWithMagicNumber, SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) );
connect( this, SIGNAL( addCameraAt( Ogre::Vector3 ) ), this, SLOT( add_camera( Ogre::Vector3 ) ) );



// slot implementation
void onButtonClicked( void )
{
emit addCameraAt(
Ogre::Vector3(
this->doubleSpinBox->value(),
this->doubleSpinBox2->value(),
this->doubleSpinBox3->value()
) );
}


You will have to register Ogre::Vector3 type to use it with signals and slots (see qRegisterMetaType for more details).

If you already read the documentation for signals and slots, go back and read it again.
And again.