1
votes

I am trying to use a Turkish translation file for my Qt project. I used Qt Linguist for generating the .ts file. The problem is when I load the translation file in my application, I am getting segmentation faults whenever I click on any item of QMenuBar.

I also have a context menu that is triggered with the contextMenuEvent of a GraphicsView in mainwindow. The program gives a segmentation fault when I try to execute the below line.

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

mContextMenu is a QMenu* and exec returns a QAction*. Basically I guess that when the translation belongs to a QAction this problem occurs. I saw the same problem when I translate the toolTips of toolButtons. How should I handle the translation of QActions and toolTips?

2
I suggest you put up a minimal code sample that shows the issue because the exec line can't be the culprit.ismail

2 Answers

0
votes

I am adding some actions to mContextMenu as below:

    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);

}

Context Menu event of graphics view is implemented as below:

    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

}

0
votes

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.