Results 1 to 8 of 8

Thread: signal/slot to add objects ?

Hybrid View

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

    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)

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

    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.

Similar Threads

  1. Replies: 2
    Last Post: 3rd May 2011, 21:22
  2. Reconnect signal/slot between two objects
    By MadBear in forum Qt Programming
    Replies: 6
    Last Post: 6th October 2010, 07:26
  3. Replies: 4
    Last Post: 2nd December 2008, 17:44
  4. Replies: 1
    Last Post: 8th November 2007, 18:11
  5. signal slot conection using a string, not a SLOT
    By rianquinn in forum Qt Programming
    Replies: 6
    Last Post: 5th February 2006, 19: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
  •  
Qt is a trademark of The Qt Company.