Undo / Redo in a toolbar?

So, I recently decided to get back into learning QT and C++ and I don’t really know what I’m doing, but I somehow managed to get the undo and redo buttons working in their own toolbar by cloning the toolbox. The problem is that sometimes when I update icons and then build the project, nothing changes. Does anyone know what might cause this?

Also, is there a way to set a button to the undo command? When i try:

connect(ui->eraserButton, &QToolButton::clicked, mCommands, &ActionCommands::ZoomIn);

From what I can gather, it seems that mCommands is private, but I tried making it public and that did not fix the issue, so is there any other way to make it zoom in?

Thanks,

Velocireed

There are already two implementations of this kind of toolbar, you can check out their code to see how it is done (the former is more like the way you are trying to implement this):

To answer your questions, modifications to .ui files and .qrc files do not always trigger updates when building. Basically Qt has it’s own precompiler (the Meta-Object Compiler, or moc for short), which is not always triggered by qmake when changes are made. The only way to guarantee that everything is updated is to delete the build folder, although I only use that as a last resort as it obviously requires rebuilding everything. Sometimes rebuild or clean+build or even just a plain build is enough too. It’s just one of the oddities of Qt that you have to live with I think.

As for connecting to the command, the simplest approach is to call whatever the actions commands function would call. If you are not doing the connect in MainWindow2, then you will not be able to access mCommands because it is private. If you made it public, it is still a member variable, so you would need to have a reference to a MainWindow2 instance and call it using that, ex: connect(ui->eraserButton, &QToolButton::clicked, mainWindow->mCommands, &ActionCommands::ZoomIn);

Thanks for the help; I will definitely check those out!

Imprint