signal/slot to add objects ?
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
Code:
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
->setObjectName
(QString::fromUtf8("toolButton_13"));
toolButton_17
->setGeometry
(QRect(10,
10,
31,
31));
doubleSpinBox
->setObjectName
(QString::fromUtf8("doubleSpinBox"));
doubleSpinBox
->setGeometry
(QRect(10,
40,
51,
22));
doubleSpinBox_2
->setObjectName
(QString::fromUtf8("doubleSpinBox_2"));
doubleSpinBox_2
->setGeometry
(QRect(70,
40,
51,
22));
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_2
= new QLabel(groupBox_6
);
label_2
->setObjectName
(QString::fromUtf8("label_2"));
label_2
->setGeometry
(QRect(70,
20,
46,
13));
label_3
= new QLabel(groupBox_6
);
label_3
->setObjectName
(QString::fromUtf8("label_3"));
label_3
->setGeometry
(QRect(130,
20,
46,
13));
my function to add cam is
Code:
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?
Re: signal/slot to add objects ?
1 Attachment(s)
Re: signal/slot to add objects ?
i have like that
Attachment 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?
Re: signal/slot to add objects ?
from what you gave, you didn't connect the clicked signal of your button to a slot, so nothing will happen
Re: signal/slot to add objects ?
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
Re: signal/slot to add objects ?
Have you read Signals & Slots documentation?
Re: signal/slot to add objects ?
I read but i still have problem
Code:
QObject::connect(pushButton,
SIGNAL(clicked
()), Form,
SLOT(close
()));
i want when i clic i add camera that mean i make like that
Code:
QObject::connect(add_button,
SIGNAL(clicked
()),
this,
SLOT(add_camera
()));
?
but how i make signal/slot of the position (add_camera in this position)
Re: signal/slot to add objects ?
You need intermediate slot to capture button click and from that slot emit signal with position constructed from values entered in your spin boxes:
Code:
// 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 );
Code:
// connection
connect( buttonWithMagicNumber, SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) );
connect( this, SIGNAL( addCameraAt( Ogre::Vector3 ) ), this, SLOT( add_camera( Ogre::Vector3 ) ) );
Code:
// 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.