信号与槽的问题
A窗体调B窗体控件,用信号槽连接不行,求原因,具体如下:
关于A:
Class A::public QMainWindow{ Q_OBJECTPublic:A(QWidget *parent = 0,Qt::WFlags flags = 0);~A();Void creatDockWindows();//在此中创建BPrivate slots:Void disposeB_TreeList(QTreeWidget * TreeWidget);//槽函数,其中得到B的控件Private: QTreeWidget *pTreeListofB;//将槽中获得的控件赋予此变量…}构造函数:A::A(QWidget *parent,Qt::WFlags flags):QMainWindow(parent,flags){ ui.setupUi(this);createDockWindows();QTreeWidget * a = pTreeListofB;//触发槽后,得到B中控件,实际上得不到}成员函数:A:: creatDockWindows(){ QDockWidget * dock = new QDockWidget(tr(“B”,this)); Dock->setAllowdAreas(Qt::LefeDockWidgetArea|Qt::RightDockWidgetArea); B temp;Connect(&temp,SIGNAL(sendTreeList(QTreeWidget*),this,SLOT(disposeB_TreeList(QTreeWidget*)));//连接信号和槽B * a = new B;dock->setWidget(a);addDockWidget(Qt::RightWidgetArea,dock);optionsMenu->addAction(dock->toggleViewAction());}槽函数:Void A::disposeB_TreeList(QTreeWidget * TreeWidget){ pTreeListOfB = TreeWidget;}
Class B: public QDialog{ Q_OBJECTPublic: B(QWidget *parent = 0);~B();Public: QTreeWidget * getTreeList(void);//获取私有控件 QTreeWidget * p_treeList;//指向控件指针Signals: Void sendTreeList(QTreeWidget *);//定义信号…}构造函数:B::B(QWidget *parent):QDialog(parent){ Ui.setupUi(this); p_treeList = getTreeList();//将私有控件赋值给公有变量 emit sendTreeList(p_treeList);//发射信号,将控件指针作为参数}成员函数:QTreeWidget * B::getTreeList(void){ p_treeList = ui.p_gsTreeList; return p_treeList;}