Qt World Summit: Register Today!

How to rename the QUndoCommand in the QWebPage undoStack?

  • I'm able to successfully access the QWebPage undoStack (QUndoStack) and obtain many of the undoStack parameters such as count, last index, and text as follows:
    qDebug()<<"undo size: " <<page()->undoStack()->count();
    int cindex = page()->undoStack()->index();
    qDebug()<<"command name:"<<page()->undoStack()->text(cindex);

    The problem I found was that that the text is always empty for common commands like cut or paste. I had hoped to fix this by setting the QUndoCommand text directly. For example:

    I thought this should work because I'm only using a const pointer but when I try it I get the error message:

    passing 'const QUndoCommand' as 'this' argument of 'void QUndoCommand::setText(const QString&)' discards qualifiers

    I have tried a number things to try and rename the command so I can see the undo sequence using QUndoView but none have been successful. Hopefully someone has a suggestion I can use.

  • Moderators

    the only thing i see you can do is this ugly trick:
    QUndoCommand* cmd = const_cast<QUndoCommand*>( page()->undoStack()->command(cindex) );

  • Gene thanks for the suggestion but unfortunately it crashes the program. The cast seems to work but when I use

    to set the text the program crashes.

  • Moderators

    please post the stack trace.

Log in to reply