|
本帖最后由 xuhaiyan8825 于 2012-7-25 22:40 编辑
cookbook上关于QT的例子,我加了一个按钮,想通过这个按钮来实现往场景中加模型,加模型的函数我单独测试了,没有问题,就是按钮的信号槽链接不成功,打了断点 ,没进去。
不知道啥原因,感觉是qt没用对,求帮助啊。
//以下是ViewerWidget类
.h文件
class ViewerWidget : public QWidget
{
public:
ViewerWidget( osg::Camera* camera, osg::Node* scene );
~ViewerWidget();
protected:
virtual void paintEvent( QPaintEvent* event )
{ _viewer->frame(); }
osg::ref_ptr<osgViewer::Viewer> _viewer;
osg::ref_ptr<osg::Group> _root;
QPushButton* _btn_addModel;
QTimer _timer;
public slots:
void AddModel();
};
.cpp文件
ViewerWidget::ViewerWidget(osg::Camera *camera, osg::Node *scene)
{
_viewer = new osgViewer::Viewer();
_root = new osg::Group();
//AddModel();
_viewer->setCamera( camera );
_viewer->setSceneData( _root.get() );
_viewer->addEventHandler( new osgViewer::StatsHandler );
_viewer->setCameraManipulator(
new osgGA::TrackballManipulator );
// Use single thread here to avoid known issues under Linux
_viewer->setThreadingModel( osgViewer::Viewer::SingleThreaded );
osgQt::GraphicsWindowQt* gw =
dynamic_cast<osgQt::GraphicsWindowQt*>(
camera->getGraphicsContext() );
if ( gw )
{
_btn_addModel = new QPushButton("add model",this);
connect(_btn_addModel,SIGNAL(clicked()),this,SLOT(AddModel()));
QVBoxLayout* layout = new QVBoxLayout;
layout->addWidget(_btn_addModel);
layout->addWidget( gw->getGLWidget() );
setLayout( layout );
}
connect( &_timer, SIGNAL(timeout()), this, SLOT(update()) );
_timer.start( 40 );
}
void ViewerWidget::AddModel()
{
/*QFileDialog *fd=new QFileDialog(this);
fd->setFilter( "OSG Files (*.osg *.dwg)" );
if(fd->exec()==QFileDialog::Accepted) // ok
{*/
QString file = QFileDialog::getOpenFileName(
this,
"open model file",
"",
"OSG Files (*.osg *.dwg)");
string sfile = XUtil::q2s(file);
//创建一个节点,读取SHP文件
osg::ref_ptr<osg::Node> node = osgDB::readNodeFile(sfile);
//添加到场景
_root->addChild(node.get());
/*}*/
} |
|