Results 1 to 2 of 2

Thread: search and replace in js with qt

  1. #1
    Join Date
    Jan 2016
    Posts
    3
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default search and replace in js with qt

    Hello,

    I have the following problem. I want to replace a string of a variable in a JavaScript file with a function in Qt.

    Qt Code:
    1. url = "qrc:/res/res/text.pdf";
    2.  
    3. void WebView::open()
    4. {
    5. QFile currentFile("qrc:/res/res/pdf-viewer.js");
    6. if(!currentFile.open(QFile::WriteOnly|QFile::Text))
    7. {
    8. return;
    9. }
    10. QTextStream in(&currentFile);
    11. s= in.readAll();
    12. s.replace("$STRINGPDF",QString(url));
    13. qDebug()<<s;
    14. currentFile.close();
    15. }
    To copy to clipboard, switch view to plain text mode 

    he finds the variable not in the specified file. Because you can see I have the absolute paths of the files specified.

    please help me

    thanks

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,593
    Thanks
    13
    Thanked 1,587 Times in 1,516 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: search and replace in js with qt

    You open the file for writing: probably fails because you cannot write to an embedded resource.
    If it opened you then attempt to read from it: probably fails silently and returns an empty string.
    You replace all occurrences of "$STRINGPDF" in the empty string.
    Your debug output is empty.

Similar Threads

  1. Problems with replace
    By feraudyh in forum Qt Tools
    Replies: 1
    Last Post: 27th March 2014, 07:54
  2. Replies: 1
    Last Post: 14th November 2012, 21:00
  3. Replace widget on tab
    By wirasto in forum Qt Programming
    Replies: 1
    Last Post: 14th August 2010, 14:01
  4. Replace keyPressEvent (dot with tab)
    By the_bis in forum Qt Programming
    Replies: 1
    Last Post: 6th June 2008, 10:43
  5. Replace text
    By Hz in forum Qt Programming
    Replies: 2
    Last Post: 22nd March 2006, 08:16

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.