我在它们之间使用两个文本编辑和两个按钮。目标是列出第一个QTextEdit中成功实现的特定文件夹中的文件。现在我想选择特定的文件,并使用它们之间的pushButton将它们发送到第二个QTextEdit,如果我要删除文件,则第二个pushButton也应该反过来。
以下是mainwindow.cpp :::
的示例代码#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
#include <QDebug>
#include <QDirIterator>
#include <QTextEdit>
#include <QTextCursor>
#include <QTextCharFormat>
#include <QWidget>
#include <QString>
QString dirPath;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->pushBrowse,SIGNAL(clicked()),this,SLOT(pushBrowseClicked()));
connect(ui->pushAdd,SIGNAL(clicked()),this,SLOT(pushAddClicked));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::pushBrowseClicked()
{
dirPath = QFileDialog::getExistingDirectory(this,"Choose a directory","/home",
QFileDialog::ShowDirsOnly);
qDebug()<<dirPath;
ui->textBrowse->setText(dirPath);
display_button_target_files(dirPath);
}
void MainWindow::display_button_target_files(QString dirPath)
{
qDebug()<<"[display_button_target_files]";
qDebug()<<dirPath;
int fileCount = 0;
QDirIterator it(dirPath);
ui->textDisplay->clear();
while (it.hasNext())
{
it.next();
QFileInfo fi = it.fileInfo();
if (fi.isFile())
{
qDebug()<<it.fileName();
ui->textDisplay->append(it.fileName());
fileCount++;
}
}
qDebug() << "Total file count: " + QString::number(fileCount);
}