+ Reply to Thread
Results 1 to 8 of 8

Thread: signal/slot to add objects ?

  1. #1
    Join Date
    Apr 2012
    Posts
    101
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default 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
    Qt Code:
    1. page_14 = new QWidget();
    2. page_14->setObjectName(QString::fromUtf8("page_14"));
    3. page_14->setGeometry(QRect(0, 0, 211, 250));
    4.  
    5.  
    6. toolBox_5 = new QToolBox(dockWidgetContents_5);
    7. toolBox_5->setObjectName(QString::fromUtf8("toolBox_5"));
    8. toolBox_5->setGeometry(QRect(0, 0, 211, 331));
    9. toolBox_5->setAutoFillBackground(false);
    10. toolBox_5->setFrameShape(QFrame::NoFrame);
    11. toolBox_5->setFrameShadow(QFrame::Plain);
    12. toolBox_5->addItem(page_14, QString::fromUtf8("Object"));
    13. toolBox_5->setItemText(toolBox_5->indexOf(page_14), QApplication::translate("MainWindow", "Camera", 0, QApplication::UnicodeUTF8));
    14.  
    15. toolButton_17 = new QToolButton(page_13);
    16. toolButton_17->setObjectName(QString::fromUtf8("toolButton_13"));
    17. toolButton_17->setGeometry(QRect(10, 10, 31, 31));
    18. toolButton_17->setText(QApplication::translate("MainWindow", "Add", 0, QApplication::UnicodeUTF8));
    19.  
    20. doubleSpinBox = new QDoubleSpinBox(groupBox_6);
    21. doubleSpinBox->setObjectName(QString::fromUtf8("doubleSpinBox"));
    22. doubleSpinBox->setGeometry(QRect(10, 40, 51, 22));
    23.  
    24. doubleSpinBox_2 = new QDoubleSpinBox(groupBox_6);
    25. doubleSpinBox_2->setObjectName(QString::fromUtf8("doubleSpinBox_2"));
    26. doubleSpinBox_2->setGeometry(QRect(70, 40, 51, 22));
    27.  
    28. doubleSpinBox_3 = new QDoubleSpinBox(groupBox_6);
    29. doubleSpinBox_3->setObjectName(QString::fromUtf8("doubleSpinBox_3"));
    30. doubleSpinBox_3->setGeometry(QRect(130, 40, 51, 22));
    31.  
    32. label = new QLabel(groupBox_6);
    33. label->setObjectName(QString::fromUtf8("label"));
    34. label->setGeometry(QRect(10, 20, 46, 13));
    35. label->setText(QApplication::translate("MainWindow", "X :", 0, QApplication::UnicodeUTF8));
    36.  
    37. label_2 = new QLabel(groupBox_6);
    38. label_2->setObjectName(QString::fromUtf8("label_2"));
    39. label_2->setGeometry(QRect(70, 20, 46, 13));
    40. label_2->setText(QApplication::translate("MainWindow", "Y :", 0, QApplication::UnicodeUTF8));
    41.  
    42. label_3 = new QLabel(groupBox_6);
    43. label_3->setObjectName(QString::fromUtf8("label_3"));
    44. label_3->setGeometry(QRect(130, 20, 46, 13));
    45. label_3->setText(QApplication::translate("MainWindow", "Z :", 0, QApplication::UnicodeUTF8));
    To copy to clipboard, switch view to plain text mode 

    my function to add cam is
    Qt Code:
    1. void OgreWidget::add_camera(const Ogre::Vector3 &pos)
    2. {
    3. char name_cam[16];
    4.  
    5. sprintf(name_cam, "cam%d", mCount_cam++);
    6.  
    7. ogreCamera1 = ogreSceneManager->createCamera(std::string(name_cam) +"PlayerCam");
    8.  
    9. ogreCamera1->setPosition(pos);
    10. ogreCamera1->lookAt(0,0,-200);
    11.  
    12. }
    To copy to clipboard, switch view to plain text mode 

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

  2. #2
    Join Date
    Apr 2012
    Posts
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: signal/slot to add objects ?

    "signal/slot" for what?!

  3. #3
    Join Date
    Apr 2012
    Posts
    101
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: signal/slot to add objects ?

    i have like that
    cam.jpg
    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?

  4. #4
    Join Date
    Nov 2010
    Posts
    82
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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

  5. #5
    Join Date
    Apr 2012
    Posts
    101
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default 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

  6. #6
    Join Date
    Jul 2010
    Location
    Indonesia
    Posts
    83
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: signal/slot to add objects ?

    Have you read Signals & Slots documentation?
    ~ We are nothing in this universe ~

  7. #7
    Join Date
    Apr 2012
    Posts
    101
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: signal/slot to add objects ?

    I read but i still have problem
    Qt Code:
    1. QObject::connect(pushButton, SIGNAL(clicked()), Form, SLOT(close()));
    To copy to clipboard, switch view to plain text mode 
    i want when i clic i add camera that mean i make like that
    Qt Code:
    1. QObject::connect(add_button, SIGNAL(clicked()), this, SLOT(add_camera()));
    To copy to clipboard, switch view to plain text mode 
    ?
    but how i make signal/slot of the position (add_camera in this position)

  8. #8
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 105 Times in 102 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default 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:
    Qt Code:
    1. // header
    2. public slots:
    3. void onButtonClicked( void );
    4. 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
    5.  
    6. signals:
    7. void addCameraAt( const Ogre::Vector3& pos );
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. // connection
    2. connect( buttonWithMagicNumber, SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) );
    3. connect( this, SIGNAL( addCameraAt( Ogre::Vector3 ) ), this, SLOT( add_camera( Ogre::Vector3 ) ) );
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. // slot implementation
    2. void onButtonClicked( void )
    3. {
    4. emit addCameraAt(
    5. Ogre::Vector3(
    6. this->doubleSpinBox->value(),
    7. this->doubleSpinBox2->value(),
    8. this->doubleSpinBox3->value()
    9. ) );
    10. }
    To copy to clipboard, switch view to plain text mode 

    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.

+ Reply to Thread

Similar Threads

  1. Replies: 2
    Last Post: 3rd May 2011, 20:22
  2. Reconnect signal/slot between two objects
    By MadBear in forum Qt Programming
    Replies: 6
    Last Post: 6th October 2010, 06:26
  3. Replies: 4
    Last Post: 2nd December 2008, 16:44
  4. Replies: 1
    Last Post: 8th November 2007, 17:11
  5. signal slot conection using a string, not a SLOT
    By rianquinn in forum Qt Programming
    Replies: 6
    Last Post: 5th February 2006, 18:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts