ebsaith
18th June 2013, 08:38
Good Day,
Created a signal in a subclass(qlabel)
connected it to slot in mainWindow class(main)
This is my code:
qlabel.h
signals:
void popUpMenu();
qlabel.cpp
void qlabel::mousePressEvent(QMouseEvent *ev)
{
if(ev->button()==Qt::RightButton)
{
emit popUpMenu();
}
...
}
main.cpp
connect(ui->label2, SIGNAL(popUpMenu()), this, SLOT(slPopUpMenu()));
...
void MainWindow::slPopUpMenu()
{
QMenu *newMenu = new QMenu(this);
newMenu->addAction(new QAction("do this", this));
newMenu->addAction(new QAction("do that", this));
newMenu->addAction(new QAction("Cancel", this));
newMenu->exec(newMenu, QCursor::pos());
}
receiving multiple errors with this code!
Where am I going wrong?
thanks
Added after 9 minutes:
Not to worry... Solved
Should have been patient before posting problem -> myBad
Solution was in main.cpp
newMenu->exec(QCursor::pos());
Kind Regards
New Prob:
Any ideas/threads out there on how to perform a function once user clicks an action on the pop up menu
Thanks
Created a signal in a subclass(qlabel)
connected it to slot in mainWindow class(main)
This is my code:
qlabel.h
signals:
void popUpMenu();
qlabel.cpp
void qlabel::mousePressEvent(QMouseEvent *ev)
{
if(ev->button()==Qt::RightButton)
{
emit popUpMenu();
}
...
}
main.cpp
connect(ui->label2, SIGNAL(popUpMenu()), this, SLOT(slPopUpMenu()));
...
void MainWindow::slPopUpMenu()
{
QMenu *newMenu = new QMenu(this);
newMenu->addAction(new QAction("do this", this));
newMenu->addAction(new QAction("do that", this));
newMenu->addAction(new QAction("Cancel", this));
newMenu->exec(newMenu, QCursor::pos());
}
receiving multiple errors with this code!
Where am I going wrong?
thanks
Added after 9 minutes:
Not to worry... Solved
Should have been patient before posting problem -> myBad
Solution was in main.cpp
newMenu->exec(QCursor::pos());
Kind Regards
New Prob:
Any ideas/threads out there on how to perform a function once user clicks an action on the pop up menu
Thanks