我在mianwindows主界面中 分别有一个QTreeWidget控件和一个QStackedWidget 控件我想实现在QTreeWidget中的item右键点击 来选择QStackedWidget中的某一个页面~
我把stackedWidget->setCurrentIndex(4);放在mianwindows的类的构造函数里,就可以成功运行,可以显示我要的界面,但是我在QTreeWidget.cpp
void myQTreeView::contextMenuEvent(QContextMenuEvent *event)//产生右键菜单事件
{
mainwindows *mainWin = new mainwindows;
newpAct = new QAction(QIcon(":/images/new.png"), tr("&New"), this);
connect(newpAct, SIGNAL(triggered()),mainWin, SLOT(test()));//弹出新建工程对话框
}
test()在mianwindows.cpp中
void mainwindows::test()
{
stackedWidget->setCurrentIndex(4);
}
这样就不好使~是不是我又新建了一个mainwindows对象,所以指向不到 我一开始的那个mainwindows对象 我有点蒙了~