我想打开一个pdf文件,只需双击QListWidget的一个元素即可.我创建了一个批处理文件来打开Acrobat Reader(reader.bat),但我想要一个特定的pdf文件:
void MainWindow::on_FileListWidget_itemDoubleClicked(QListWidgetItem *item)
{
QFile SelectedModel(Current_Path + "/Template/" + item->text());
QString FileName;
FileName = (Current_Path + "/Template/" + item->text());
::system("e:\\reader.bat");
}
Run Code Online (Sandbox Code Playgroud)
1)我不知道从QFile或QString可以更好的是从QListWidget中识别和选择文件; 2)我不知道如何将文件添加到命令中打开Acorbat Reader(在显示的行中我可以打开程序但不能打开我的文件).任何的想法?
我正在尝试在文本文件中搜索字符串; 我的目的是只有在我的文本文件中没有写入它时才写它.
这是我的函数(我不知道如何放入while循环):
QFile MyFile("text.txt");
MyFile.open(QIODevice::ReadWrite);
QTextStream in (&MyFile);
while(!MyFile.atEnd())
{ //do something to search string inside }
MyFile.close();
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?从Qt的帮助,方法"包含"仅适用于const变量; 我可以用它来寻找我的字符串吗?
在一个小部件中,我放了两个 QPushButton(让我们说左边的“OK”和右边的“EXIT”)。当我使用鼠标按下它们时,它们会定期工作。假设我想使用 TAB 键从一个切换到另一个:这可能吗?怎么能做到这一点?
假设我有一个QLabel多行文本;这个多行文本来自一个文本文件:我打开文本文件,一次读取一行并将读取的行放入QLabel后跟“\n”(CR)。
当我到达文件末尾时,我会QLabel显示每行所有读取的文本行。在读取阶段,我能够检测读取的行是否包含搜索的单词:在这种情况下,我会将整行放在粗体字符中,而所有其他行仍然不使用粗体字体。
我怎样才能做到这一点?
从QByteArray开始,我想在我的QByteArray中搜索"\n"char并将所有字符从头开始加到"\n"并将它们保存在QString中; 之后,我将传递给下一个字节直到下一个"\n"并将它们保存到一个新的QString中
QByteArray MyArray= (all data from my previous process);
quint16 ByteArrayCount = MyArray.count(); // number of bytes composing MyArray
quint16 mycounter;
QString myString;
while (mycounter < ByteArrayCount)
{
if(MyArray[mycounter] != "\n")
myString.append(MyArray[mycounter]);
mycounter++;
}
Run Code Online (Sandbox Code Playgroud)
这将附加新行之前的所有字节; 我的问题是如何评估MyArray [counter],因为我无法在计数器增加时检查每个字节.
解?
qt ×5
c++ ×2
external ×1
file ×1
qbytearray ×1
qlabel ×1
qpushbutton ×1
qstring ×1
search ×1
text ×1