Here the count is used only to isolate one selected item
And if for any reason at all, the count is NOT 1, nothing will be executed. Do us both a favor and put a
qDebug() << "items.count() = " << items.count();
qDebug() << "items.count() = " << items.count();
To copy to clipboard, switch view to plain text mode
line in there after you retrieve the selected items, just to prove to both of us whether the count is anything other than one. You can't claim the code doesn't work when you don't demonstrate that the if() clause is ever executed.
It also isn't clear how you get to DiagramWindow:: increaseSize() in the first place. Is this a slot? What signal is it connected to? Do you have any evidence that the method is ever called?
the dynamic_cast is used to ensure it is of the correct type in the original example.
Yes, but you should also realize that dynamic_cast<> returns a NULL pointer if the type is not correct, so your code as it stands now is guaranteed to blow up since you don't check for NULL but just go ahead and use the pointer no matter what.
--Edit--
Ummm, I just took a bit closer look at the DiagramWindow.cpp file you posted earlier. See if you can spot anything suspicious about this code:
void DiagramWindow::createActions()
{
// ... stuff omitted
increaseSizeAction
= new QAction(tr
("Increase"),
this);
increaseSizeAction
->setIcon
(QIcon(":/images/increaseSize.png"));
connect(increaseSizeAction, SIGNAL(triggered(bool)),
this, SLOT(increaseSize()));
decreaseSizeAction
= new QAction(tr
("Decrease"),
this);
decreaseSizeAction
->setIcon
(QIcon(":/images/decreaseSize.png"));
connect(increaseSizeAction, SIGNAL(triggered(bool)),
this, SLOT(decreaseSize()));
normalSizeAction
= new QAction(tr
("Normal"),
this);
normalSizeAction
->setIcon
(QIcon(":/images/normalSize.png"));
connect(increaseSizeAction, SIGNAL(triggered(bool)),
this, SLOT(normalSize()));
}
void DiagramWindow::createActions()
{
// ... stuff omitted
increaseSizeAction = new QAction(tr("Increase"),this);
increaseSizeAction->setIcon(QIcon(":/images/increaseSize.png"));
connect(increaseSizeAction, SIGNAL(triggered(bool)),
this, SLOT(increaseSize()));
decreaseSizeAction = new QAction(tr("Decrease"),this);
decreaseSizeAction->setIcon(QIcon(":/images/decreaseSize.png"));
connect(increaseSizeAction, SIGNAL(triggered(bool)),
this, SLOT(decreaseSize()));
normalSizeAction = new QAction(tr("Normal"),this);
normalSizeAction->setIcon(QIcon(":/images/normalSize.png"));
connect(increaseSizeAction, SIGNAL(triggered(bool)),
this, SLOT(normalSize()));
}
To copy to clipboard, switch view to plain text mode
Bookmarks