使用QText浏览器打开桌面

时间:2010-12-20 17:53:09

标签: c++ qt

现在我在QText浏览器中显示类似/ home / binary /的内容。现在我希望通过单击此文本打开文件夹。怎么做 ?提前致谢

这是我的示例代码。我显示结果 小号

bool MainWindow::displayResult(multimap<string,
     

的字符串&GT; &amp; resultMap,string&amp; filePath)       {           multimap :: iterator iter;           bool fileStatus = false;           int noOfLocFound = 0,forAppending = 0;           QString no;

    noOfLocFound = resultMap.size();

    if ( noOfLocFound != 0 )
        ui->textBrowser->append( "<i>File found at <b>" + no.setNum (
     

noOfLocFound)+“locations”);

    for ( forAppending = 0,iter = resultMap.begin(); iter !=
     

resultMap.end(); ITER ++,   forAppending ++)           {               string file = iter-&gt; first;               string dir = iter-&gt; second;

        if ( forAppending == 0)
            filePath.append(dir);
        else
            filePath.append(","+dir);

        QString qdir = QString::fromStdString(dir);

        cout << "Display";

        ui->textBrowser->append( qdir );
        fileStatus = true;

    }

    if ( fileStatus == false )
    {
        ui->textBrowser->append("File not
     

发现“);               返回false;           }

    return true;
}

1 个答案:

答案 0 :(得分:0)

通过“打开文件夹”,您的意思是,打开一个文件对话框,供用户选择给定目录中的内容吗?

如果是这样,您可能希望将QTextBrowser的点击信号连接到看起来像这样的插槽:

// connect events, in MyWindow constructor, or whereever...
connect(textbrowser, SIGNAL(mousePressEvent(QMouseEvent*)), this, SLOT(openFileDialog(QMouseEvent*)));

void MyWindow::openFileDialog(QMouseEvent* event) {
    Q_UNUSED(event);

    QStringList files = QFileDialog::getOpenFileNames(this, "Select a file...",
        textbrowser.plainText());

    // do something with the files here...
}