【问题标题】:open desktop using QText Browser使用 QText 浏览器打开桌面
【发布时间】:2010-12-20 17:53:09
【问题描述】:

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

这是我的示例代码。我正在显示结果 s

bool MainWindow::displayResult(multimap<string,

字符串> &resultMap, 字符串 &filePath) { multimap::iterator 迭代器; 布尔文件状态 = 假; int noOfLocFound = 0, forAppending = 0; QString 没有;

    noOfLocFound = resultMap.size();

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

noOfLocFound ) + "位置");

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

resultMap.end();迭代++, forAppending++) { 字符串文件 = iter->first; string dir = iter->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

找到"); 返回假; }

    return true;
}

【问题讨论】:

    标签: c++ qt


    【解决方案1】:

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

    如果是这样,您可能希望将 QTextBrowser 的 clicked 信号连接到类似于以下内容的插槽:

    // 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...
    }
    

    【讨论】:

    • 让我以另一种方式提出我的问题 ---- 现在我在 QText 浏览器中显示结果。结果将类似于 /home/User/ 、 /media/Arena/ 等。现在我想通过单击显示在 QText 浏览器中的此结果来打开此文件夹。但我不知道该怎么做。在其中一个线程中,有人要求我使用已单击的锚点,但我不知道如何使用它。那么你能否给我一段关于如何做到这一点的代码。提前坦克斯。 PS我正在使用QT creato
    • 也许如果您发布一些现有代码,很容易看出要完成什么?
    猜你喜欢
    • 1970-01-01
    • 2011-12-28
    • 1970-01-01
    • 2010-12-26
    • 1970-01-01
    • 2019-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多