1

我正在尝试为我的 Qt 项目使用土耳其语翻译文件。我使用 Qt Linguist 生成 .ts 文件。问题是当我在我的应用程序中加载翻译文件时,每当我单击 QMenuBar 的任何项目时都会出现分段错误。

我还有一个上下文菜单,它由主窗口中的 GraphicsView 的 contextMenuEvent 触发。当我尝试执行以下行时,程序给出了分段错误。

mContextMenu->exec(event->globalPos());

mContextMenu 是一个 QMenu* 并且 exec 返回一个 QAction*。基本上我猜当翻译属于 QAction 时,就会出现这个问题。我在翻译toolButtons的toolTips时看到了同样的问题。我应该如何处理 QActions 和 toolTips 的翻译?

4

2 回答 2

0

The problem I described above is solved when I used QApplication instead of a customized class that inherits QApplication. Inside of the customized class, bool QApplication::notify ( QObject * receiver, QEvent * e ) function was implemented. When I used QApplication directly, all translations were loaded correctly and no problems ocuured regarding the QAction items and toolTips.

于 2012-12-21T09:39:14.253 回答
0

我正在向 mContextMenu 添加一些操作,如下所示:

    void RadarView::prepareMainMenu() {
mContextMenu = new QMenu();
//showLineAction->setShortcut(QKeySequence("Alt+Shift+L"));
mpStartRulerAction = new QAction(QObject::tr("Start Ruler"), this);
mContextMenu->addAction(mpStartRulerAction);
connect(mpStartRulerAction, SIGNAL(triggered()), this,
        SLOT(menuStartRulerClicked()));
mpStartRulerAction->setProperty("TYPEVIEW", MV_StartRuler);

mpEndRulerAction = new QAction(QObject::tr("End Ruler"), this);
mContextMenu->addAction(mpEndRulerAction);
connect(mpEndRulerAction, SIGNAL(triggered()), this, SLOT(menuEndRulerClicked()));
mpEndRulerAction->setProperty("TYPEVIEW", MV_EndRuler);

mpCriticalRegionAction = new QAction(QObject::tr("Critical Region"), this);
mContextMenu->addAction(mpCriticalRegionAction);
connect(mpCriticalRegionAction, SIGNAL(triggered()), this, SLOT(menuDefineCriticalRegionClicked()));
mpCriticalRegionAction->setProperty("TYPEVIEW", MV_Critical_Region);

mpAScopeAction = new QAction(QObject::tr("A-Scope Line"), this);
mContextMenu->addAction(mpAScopeAction);
connect(mpAScopeAction, SIGNAL(triggered()), this, SLOT(menuAddAScopeLine()));
mpAScopeAction->setProperty("TYPEVIEW", MV_A_Scope);

}

图形视图的上下文菜单事件实现如下:

    void RadarView::contextMenuEvent(QContextMenuEvent * event) {
LOGGER_START
//check if the item has its own  context menu...
QList<QGraphicsItem*> items = this->items(event->pos());

if (items.size() != 0) {
    bool isValid = true;
    for (int i = 0; i < items.size(); ++i) {
        QGraphicsRulerLineItem *rulerLineItem = NULL;
        rulerLineItem = dynamic_cast<QGraphicsRulerLineItem*> (items[i]);
        if (rulerLineItem != NULL || dynamic_cast<AScopeLineItem*> (items[i]) || dynamic_cast<PpiTargetItem*> (items[i])){
            isValid = false;
        }
        else {
            PpiPlotItem *targetItem = NULL;
            targetItem = dynamic_cast<PpiPlotItem*> (items[i]);
            if (targetItem != NULL) {
                isValid = false;
                if (currentVisibleMenuItems.contains(0)) {
                    startItem = targetItem;
                } else if (currentVisibleMenuItems.contains(1)) {
                    endItem = targetItem;
                }
            }
        }
    }

    if (isValid == true) {

        if(currentVisibleMenuItems.size() ==0)
            return;
        //Get last clicked Position.
        mLastClickedPos = event->pos();
        //show  menu of RadarView...
        mpRightClickAction = mContextMenu->exec(event->globalPos());
    } else {
        QGraphicsView::contextMenuEvent(event);
    }

}

LOGGER_END

}

于 2012-12-19T11:34:43.180 回答