我正在尝试为我的Qt项目使用土耳其语翻译文件。我使用Qt Linguist生成.ts文件。问题是当我在我的应用程序中加载翻译文件时,每当我点击QMenuBar的任何项目时,我都会遇到分段错误。
我还有一个上下文菜单,它是用mainwindow中GraphicsView的contextMenuEvent触发的。当我尝试执行以下行时,程序会出现分段错误。
mContextMenu->exec(event->globalPos());
mContextMenu是一个QMenu *,exec返回一个QAction *。基本上我猜想当翻译属于QAction时会出现这个问题。当我翻译toolButtons的工具提示时,我看到了同样的问题。我该如何处理QActions和工具提示的翻译?
答案 0 :(得分: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
}
答案 1 :(得分:0)
当我使用QApplication而不是继承QApplication的自定义类时,我解决了上面描述的问题。在自定义类的内部,实现了bool QApplication :: notify(QObject * receiver,QEvent * e)功能。当我直接使用QApplication时,所有翻译都被正确加载,并且没有关于QAction项目和工具提示的问题。