简体   繁体   English

以编程方式访问QFiledialog

[英]Access QFiledialog programmatically

I am trying to do the system testing in QT created application. 我正在尝试在QT创建的应用程序中进行系统测试。 I have encountered the below problem. 我遇到了以下问题。 Open menu action in my application triggers a QFileDialog. 我的应用程序中的打开菜单操作会触发QFileDialog。 I have handle(pointer) for the same. 我有相同的handle(pointer)。 But i am not sure how to select the required file and trigger the open action. 但是我不确定如何选择所需的文件并触发打开操作。

Below things i have tried: 以下是我尝试过的事情:

fileDial->setDirectory("xxxx");
fileDial->selectFile(xxx");
fileDial->fileSelected("xxxx");
fileDial->selectNameFilter("xxx");

and note that i haven't get any action for the 请注意,我没有采取任何行动

fileDial->findChildren<QAction*>(). 

QFileDialog is just a wrapper on a system dialog. QFileDialog只是系统对话框上的包装器。 That's why it's useless to search for any QActions there. 这就是为什么在那里搜索任何QActions都没用的原因。 Instead if you run you program in Windows you can use WIN API to deal with the dialog. 相反,如果您在Windows中运行程序,则可以使用WIN API处理该对话框。

Here is a simple example where some text is placed in the file name control and Open button is clicked: 这是一个简单的示例,其中在文件名控件中放置了一些文本,然后单击了“打开”按钮:

#define WAIT(A) while (!(A)) {}
HWND dialogHandle, button, edit, combo, comboEx;
WAIT(dialogHandle = FindWindow(NULL, L"Open"));
WAIT(button = FindWindowEx(dialogHandle, NULL, L"Button", L"&Open"));
WAIT(comboEx = FindWindowEx(dialogHandle, comboEx, L"ComboBoxEx32", NULL));
WAIT(combo = FindWindowEx(comboEx, combo, L"ComboBox", NULL));
WAIT(edit = FindWindowEx(combo, NULL, L"Edit", NULL));

char text[] = "arc.h";
SendMessageA(edit, WM_SETTEXT, 0, (LPARAM) text);

SendMessage(button, BM_CLICK, 0, 0);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM