1

I am working with Qt controls. I want to create a text file and save it locally on a given path using javascript. I tried many of the code snippets available here, but none worked (may be i missed with the working code).

From visualc++, i enabled the following settings for QGraphicsWebView:

m_pWebView = new QGraphicsWebView();
QWebSettings *ws = m_pWebView->settings();
ws->setAttribute(QWebSettings::WebGLEnabled, true);
ws->setAttribute(QWebSettings::PluginsEnabled, true);
ws->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);
ws->setAttribute(QWebSettings::JavascriptCanAccessClipboard, true);
ws->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, true);
ws->setAttribute(QWebSettings::LocalStorageEnabled, true);
ws->enablePersistentStorage(QString("C:\\demo"));

What else i am missing ??

Please help me, devs... Thanks..

Chintan Soni
  • 24,761
  • 25
  • 106
  • 174

1 Answers1

1

Have you tried SaveFile.js? Here you can find the official links and a brief explanation of how it works. If QGraphicsWebView supports the download attribute of a tags, then it should work.

Community
  • 1
  • 1
kol
  • 27,881
  • 12
  • 83
  • 120
  • Thank you sir. I went through your answer and tried to apply the same as you said, but i got 4 errors with the same initials `QSslSocket: cannot call unresolved function...` as shown here: http://stackoverflow.com/questions/10846536/unresolved-functions-while-working-with-qsslsocket – Chintan Soni Oct 25 '13 at 08:36
  • Sir, where is this `.pro` file located ? And what would be the file name with `.pro` extension ? – Chintan Soni Oct 25 '13 at 10:17
  • Without working with `.pro` file, after copying `libeay32.dll` and `ssleay32.dll`, when i again ran my code, no errors were found, also i didn't find any output. I wrote your code in my html file inside body tag insode script tag. What this code will do, that you answered ? – Chintan Soni Oct 25 '13 at 10:24
  • Try this: (1) Open http://eligrey.com/demos/FileSaver.js/ in your QGraphicsWebView using its `load` method. (2) Save a text file using the page which opened (use the "Saving text" example). (3) Try to figure out whether the file has been saved and where. – kol Oct 25 '13 at 11:50
  • I tried this as you said but nothing happened, clicking on save button. I tried using Firefox, it prompted to save the file. But didn't work with QGraphicsWebView. – Chintan Soni Oct 25 '13 at 12:09
  • QGraphicsWebView has a `page()` (of type `QWebPage`), which has two important signals: `downloadRequested` and `unsupportedContent`. These are emitted when you click on a link, so I think you should connect these signals to proper slots, see the answer here: http://stackoverflow.com/questions/16346219/how-to-download-files-from-qwebview – kol Oct 25 '13 at 13:42
  • Hmm. One last idea: try to a save a txt from the FileSaver.js demo page in the Arora browser (https://code.google.com/p/arora/). It's open-source and based on Qt+WebKit, so if it is able to save the txt, then you can use Qt debugger to find out how it works. (I did this in the past when I had to figure out how it handles NTLM proxy passwords.) – kol Oct 26 '13 at 09:13