0

I am trying to do the system testing in QT created application. I have encountered the below problem. Open menu action in my application triggers a QFileDialog. I have handle(pointer) for the same. 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*>(). 
Anbu
  • 91
  • 7

1 Answers1

2

QFileDialog is just a wrapper on a system dialog. That's why it's useless to search for any QActions there. Instead if you run you program in Windows you can use WIN API to deal with the dialog.

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);
Ezee
  • 4,214
  • 1
  • 14
  • 29
  • Thanks for your reply. I need multiplatform(win/mac) solution – Anbu Sep 07 '14 at 13:02
  • @anbu-velusamy If you use static methods of QFileDialog it uses native system dialogs of OS. In this case it's impossible have a multiplatform solution, because it's not implemented in Qt. You can code solutions for both win and mac. But if you create QFileDialog with "show" it will be a usual Qt dialog and you can control it. – Ezee Sep 08 '14 at 06:55
  • Thank you. Is there way to access in Mac? – Anbu Sep 11 '14 at 19:44
  • I can't help you with Mac. You can create another specific question for this. – Ezee Sep 12 '14 at 05:35