我已使用以下代码在QTreeView项目中实现了上下文菜单
MyDerivedQTreeView->setModel(MyDerivedQAbstractItemModel);
MyDerivedQTreeView->setContextMenuPolicy(Qt::CustomContextMenu);
connect(MyDerivedQTreeView,
SIGNAL(customContextMenuRequested(const QPoint &)),
MyDerivedQAbstractItemModel(),
SLOT(contextualMenu(const QPoint &)));
void MyDerivedQAbstractItemModel::contextualMenu(const QPoint& point)
{
QMenu *menu = new QMenu;
menu->addAction(QString("Test Item"), this, SLOT(test_slot()));
menu->exec(MyDerivedQTreeView->mapToGlobal(point));
}
Run Code Online (Sandbox Code Playgroud)
调用MyDerivedQAbstractItemModel :: contextualMenu(),我可以看到上下文菜单.
问题是只有当用户右键单击某个项目并且应根据所选项目进行自定义时,才能看到上下文菜单.
如何从QPoint信息中选择/选择哪个项目?我在Qt 4.5.3.
我有以下代码来复制文件
sprintf(command, "copy /Y %s %s", sourceFile, targetFile);
system(command);
Run Code Online (Sandbox Code Playgroud)
它的工作原理除了dos窗口显示非常烦人.
我正在尝试使用CreateProcess()(对于WINNT使用#ifdef),但不确定如何设置相同的命令行.在没有显示dos窗口的情况下,在C(在Windows上)复制文件的任何其他选项?
我正在尝试读取它的内容的二进制文件它为每个组件有两组行第一行的第二个最后一个字符表示组件文件的类型(^ A表示汇编,^ B表示部分)如果类型是^一个我需要解析在明年与开始行中指定的文件名^ @
àtype^@^Aà
name^@assembly1
àtype^@^Aà
name^@assembly2
àtype^@^Bà
name^@apart1
àtype^@^Bà
name^@apart2
Run Code Online (Sandbox Code Playgroud)
当我尝试解析此文件时,我无法读取文件中的二进制字符.第一行包含二进制字符(à),所以我得到一个空行.第二行在名称后面有^ @,所以我只得到'name'而len是4.这是我的代码片段
FILE *fp;
char line[256];
fp = fopen(name, "rb");
fgets(line, 256, fp);
printf("line %s\n", line);
printf("len %d\n\n", strlen(line));
fgets(line, 256, fp);
printf("line %s\n", line);
printf("len %d\n\n", strlen(line));
Run Code Online (Sandbox Code Playgroud)
这是输出
line
len 0
line name
len 4
Run Code Online (Sandbox Code Playgroud)
我的目标是解析组件的类型(^ A或^ B),然后获取组件的名称.请帮忙指出如何解决这个问题.