小编use*_*297的帖子

在QTreeView中为特定项添加右键单击菜单

我用Qt Creator用c ++编写了一个Qt桌面应用程序.

我在主窗口中声明了一个treeView和一个兼容的模型.

现在,我想为树项目提供一个右键单击菜单.不是针对所有项目,而是针对其中的一部分,例如:对于具有偶数索引的树元素.

我尝试使用以下代码添加一个简单的上下文菜单:

在.h文件中:

QStandardItemModel* model;
QMenu* contextMenu;
QAction* uninstallAction;
private slots:
    void uninstallAppletClickedSlot();
Run Code Online (Sandbox Code Playgroud)

并在.cpp文件中:

在构造函数中:

ui->treeView->setModel(model);
contextMenu = new QMenu(ui->treeView);
ui->treeView->setContextMenuPolicy(Qt::ActionsContextMenu);
uninstallAction = new QAction("Uninstall TA",contextMenu);
ui->treeView->addAction(uninstallAction);
connect(uninstallAction, SIGNAL(triggered()), this, SLOT(uninstallAppletClickedSlot()));
Run Code Online (Sandbox Code Playgroud)

和一个插槽:

void MainWindow::uninstallAppletClickedSlot()
{

}
Run Code Online (Sandbox Code Playgroud)

这段代码给了我一个带有想要动作的上下文菜单,但你知道我怎么能只为QStandardItem带有偶数索引的s 添加这个动作?

顺便说一句,我是通过以下方式向treeView添加项目:

void MainWindow::AddItem(QString name)
{
QStandardItem *parentItem = model->invisibleRootItem();
QStandardItem *app = new QStandardItem(name);
parentItem->appendRow(app);
}
Run Code Online (Sandbox Code Playgroud)

我google了很多,但一无所获:(

提前致谢!

qt right-click qtreeview qstandarditem

30
推荐指数
1
解决办法
3万
查看次数

如何在c ++和QML应用程序中使用qrc?

我在Windows7上用c ++ qnd Qt Creator(QML)编写了一个Qt Quick Desktop应用程序.现在我必须部署它,我需要隐藏qml文件和图像(意思是:将它们放在资源等中)

我已经读过使用.qrc文件有一个很好的方法.我阅读了有关这些文件的文档,并为我的应用程序创建了一个文件,如下所示:

<RCC>
<qresource prefix="/">
    <file>qml/GenericHostApplicationQML/myMain.qml</file>
    <file>qml/GenericHostApplicationQML/content/PressAndHoldButton.qml</file>
    <file>qml/GenericHostApplicationQML/content/TextButton.qml</file>
    <file>qml/GenericHostApplicationQML/content/pics/advancedsettings.png</file>
    <file>qml/GenericHostApplicationQML/content/pics/cnruninstall.png</file>
    <file>qml/GenericHostApplicationQML/content/pics/dialog_cancel.png</file>
    <file>qml/GenericHostApplicationQML/content/pics/folder_explore.png</file>
    <file>qml/GenericHostApplicationQML/content/pics/gnome_session_switch.png</file>
    <file>qml/GenericHostApplicationQML/content/pics/mail2_send.png</file>
    <file>qml/GenericHostApplicationQML/content/pics/Picture1.png</file>
    <file>qml/GenericHostApplicationQML/content/pics/Picture2.png</file>
</qresource>
Run Code Online (Sandbox Code Playgroud)

在main.cpp中,我正在加载Main.qml文件,如:

int main(int argc, char *argv[])
{
   QApplication app(argc, argv);
   QDeclarativeView view;
   view.setSource(QUrl::fromLocalFile("qml/GenericHostApplicationQML/myMain.qml"));
   view.show();
   return app.exec();
}
Run Code Online (Sandbox Code Playgroud)

我试图从Resources.qrc中读取myMain.qml文件,如:

view.setSource(QUrl(":/qml/GenericHostApplicationQML/myMain.qml"));//I added the ":/"
Run Code Online (Sandbox Code Playgroud)

但我有这个错误:

file:///qml/GenericHostApplicationQML/myMain.qml: File not found 
Run Code Online (Sandbox Code Playgroud)

当我尝试这个:

view.setSource(QUrl::fromLocalFile(":/qml/GenericHostApplicationQML/myMain.qml"));
Run Code Online (Sandbox Code Playgroud)

我明白了:

file:///C:/Users/ayalafre/Desktop/ghaQML/GenericHostApplicationQML-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Release/:/qml/GenericHostApplicationQML/myMain.qml: File not found
Run Code Online (Sandbox Code Playgroud)

好像我的Qt不知道该怎么办:":/".

我必须使用.qrc文件:

  • 加载myMain.qml文件
  • 使用导入到myMain.qml中的qml文件
  • 在我的qml文件中使用图像

你能解释一下有什么问题吗?以及为了在c ++和qml中使用.qrc我必须做些什么?

非常感谢:)

c++ qt deploying qml

12
推荐指数
1
解决办法
2万
查看次数

QML桌面中的RadioButton

我的页面中有3个单选按钮(QML桌面应用程序),一旦我选中了一个,我希望所有其他按钮都不被选中.我尝试使用CheckableGroup我在帮助中找到的代码

CheckableGroup { id: group }
Row {
 id: row
 spacing: platformStyle.paddingMedium
 RadioButton {
     id: button1
     text: "1"
     platformExclusiveGroup: group
 }
 RadioButton {
     id: button2
     text: "2"
     platformExclusiveGroup: group
 }
 RadioButton {
     id: button3
     text: "3"
     platformExclusiveGroup: group
     checked: true
 }
}
Run Code Online (Sandbox Code Playgroud)

但我得到一个错误"platformExclusiveGroup不是一个有效的属性名称"我尝试了另一种解决方案

RadioButton{
  id:rbtnDecimal1;
  width: 130;
  onClicked:{
    if(checked){
      rbtnHexadecimal1.checked=false;
      rbtnString1.checked=false;
    }
  }
  text: "Decimal Data";
  anchors.left:rbtnHexadecimal1.right
}
Run Code Online (Sandbox Code Playgroud)

当一个按钮被选中时,所有其他按钮都被取消选中,但是其他按钮会被检查,直到我将鼠标移到它们上面 - 它们变为未被检查.

任何想法如何实现它?

desktop qt radio-button qml

5
推荐指数
2
解决办法
4818
查看次数

ENVDTE - 将新项目添加到现有解决方案并将其定位到特定文件夹中

我在visual studio 2012上使用c#编写了一个Visual Studio向导模板.

我遵循MSDN步骤:我创建了一个VS模板,然后我创建了一个类库项目,其中包含一个实现IWizard接口的类,我配置了.vstemplate文件等...

在我的类库项目中,我从计算机中的某个目录复制现有解决方案,我将新生成的项目添加到该解决方案,然后运行它.

我这样做:

public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
        {
            solutionDir = replacementsDictionary["$solutiondirectory$"];
            destProjectDir = replacementsDictionary["$destinationdirectory$"];
            projName = replacementsDictionary["$specifiedsolutionname$"];
            EmulationDir = @"MY_PATH\TestSln";
            DirectoryCopy(EmulationDir, solutionDir);
            dte = (DTE2)automationObject;          

        }

public void RunFinished()
        {
            Solution2 solution;
            Project p;
            solution = (Solution2)dte.Solution;
            solution.Open(solutionDir + "\\TestSln.sln");

            p = solution.AddFromFile(destProjectDir + "\\" + projName + ".vcxproj");

        }
Run Code Online (Sandbox Code Playgroud)

但是我必须将新项目添加到解决方案的特定子文件夹中:上面的代码直接将新项目添加到解决方案中,我想将它添加到solutionDir\apps中.

你知道怎么办吗?谢谢!!

c# solution envdte visual-studio-2012

3
推荐指数
1
解决办法
3380
查看次数

无法在循环C++中打开文件

我有一个c ++应用程序,它具有以下代码:

for (int i = 0; i < ALL_EPID_CERTS_LENGTH; i++)
            {
            std::ifstream file(; 
            file.open(path.append(ALL_EPID_CERTS_1_0[i]), std::ios::in | std::ios::binary); 
            if(file.is_open()) 
            {
                // get the length of the file 
                file.seekg(0, ios::end); 
                size_t fileSize = file.tellg(); 
                file.seekg(0, ios::beg);
                // create a vector to hold all the bytes in the file
                vector<byte> data(fileSize, 0);
                // read the file
                file.read(reinterpret_cast<char*>(&data[0]), fileSize);             
                byte *tempCerts = new byte[data.size()+1];
                memset(tempCerts,0,fileSize+1);
                std::copy(data.begin(), data.begin()+(data.size()), tempCerts);
                // !!!!check if NULL and place for NULL are needed
                for (int j = 0; …
Run Code Online (Sandbox Code Playgroud)

c++ loops file

0
推荐指数
1
解决办法
309
查看次数