Html parser
- 
Hi, If it's only to get the URL contained in the href attribute then using a regex like href="(.*)"with QRegularExpression should do the job.@SGaist said in Html parser: href="(.*)" can you give some example how to extract href with regex <html> 
 <head><title>Index of /satfiles/</title></head>
 <body bgcolor="white">
 <h1>Index of /satfiles/</h1><hr><pre><a href="../">../</a>
 <a href="test1.txt">test1.txt</a> 28-Oct-2018 08:08 14
 <a href="test2.txt">test2.txt</a> 28-Oct-2018 08:09 13
 <a href="yazmifiletest.ts">yazmifiletest.ts</a> 28-Oct-2018 08:09 30
 </pre><hr></body>
 </html>
- 
@SGaist said in Html parser: href="(.*)" can you give some example how to extract href with regex <html> 
 <head><title>Index of /satfiles/</title></head>
 <body bgcolor="white">
 <h1>Index of /satfiles/</h1><hr><pre><a href="../">../</a>
 <a href="test1.txt">test1.txt</a> 28-Oct-2018 08:08 14
 <a href="test2.txt">test2.txt</a> 28-Oct-2018 08:09 13
 <a href="yazmifiletest.ts">yazmifiletest.ts</a> 28-Oct-2018 08:09 30
 </pre><hr></body>
 </html>
- 
Hi 
 Something likeQString html = R"( <html> <head><title>Index of /satfiles/</title></head> <body bgcolor="white"> <h1>Index of /satfiles/</h1><hr><pre><a href="../">../</a> <a href="test1.txt">test1.txt</a> 28-Oct-2018 08:08 14 <a href="test2.txt">test2.txt</a> 28-Oct-2018 08:09 13 <a href="yazmifiletest.ts">yazmifiletest.ts</a> 28-Oct-2018 08:09 30 </pre><hr></body> </html>)"; QString regex = R"(href="([^"]*))"; ---- QRegularExpression re(regex); QRegularExpressionMatchIterator i = re.globalMatch(html); while (i.hasNext()) { QRegularExpressionMatch match = i.next(); qDebug().noquote() << match.captured(); }Gets you href="../ href="test1.txt href="test2.txt href="yazmifiletest.tsyou can use 
 https://regexr.com/
 to tweak the expression to match exactly.
- 
@SGaist said in Html parser: href="(.*)" can you give some example how to extract href with regex <html> 
 <head><title>Index of /satfiles/</title></head>
 <body bgcolor="white">
 <h1>Index of /satfiles/</h1><hr><pre><a href="../">../</a>
 <a href="test1.txt">test1.txt</a> 28-Oct-2018 08:08 14
 <a href="test2.txt">test2.txt</a> 28-Oct-2018 08:09 13
 <a href="yazmifiletest.ts">yazmifiletest.ts</a> 28-Oct-2018 08:09 30
 </pre><hr></body>
 </html>Try out with the QRegularExpression example In contrast to the single line version of the QRegExp example you can test short text sections. 
- 
Hi 
 Something likeQString html = R"( <html> <head><title>Index of /satfiles/</title></head> <body bgcolor="white"> <h1>Index of /satfiles/</h1><hr><pre><a href="../">../</a> <a href="test1.txt">test1.txt</a> 28-Oct-2018 08:08 14 <a href="test2.txt">test2.txt</a> 28-Oct-2018 08:09 13 <a href="yazmifiletest.ts">yazmifiletest.ts</a> 28-Oct-2018 08:09 30 </pre><hr></body> </html>)"; QString regex = R"(href="([^"]*))"; ---- QRegularExpression re(regex); QRegularExpressionMatchIterator i = re.globalMatch(html); while (i.hasNext()) { QRegularExpressionMatch match = i.next(); qDebug().noquote() << match.captured(); }Gets you href="../ href="test1.txt href="test2.txt href="yazmifiletest.tsyou can use 
 https://regexr.com/
 to tweak the expression to match exactly.thakk you for giving solution i want like this only i have solved my problem. 
- 
Hi 
 Something likeQString html = R"( <html> <head><title>Index of /satfiles/</title></head> <body bgcolor="white"> <h1>Index of /satfiles/</h1><hr><pre><a href="../">../</a> <a href="test1.txt">test1.txt</a> 28-Oct-2018 08:08 14 <a href="test2.txt">test2.txt</a> 28-Oct-2018 08:09 13 <a href="yazmifiletest.ts">yazmifiletest.ts</a> 28-Oct-2018 08:09 30 </pre><hr></body> </html>)"; QString regex = R"(href="([^"]*))"; ---- QRegularExpression re(regex); QRegularExpressionMatchIterator i = re.globalMatch(html); while (i.hasNext()) { QRegularExpressionMatch match = i.next(); qDebug().noquote() << match.captured(); }Gets you href="../ href="test1.txt href="test2.txt href="yazmifiletest.tsyou can use 
 https://regexr.com/
 to tweak the expression to match exactly.
- 
- 
@aha_1980 said in Html parser: https://solarianprogrammer.com/2011/10/16/cpp-11-raw-strings-literals-tutorial error: 'R' was not declared in this scope 
 QString qHtml = R"(<button type="button">Click Me!</button>)";
 ^
- 
@aha_1980 said in Html parser: https://solarianprogrammer.com/2011/10/16/cpp-11-raw-strings-literals-tutorial error: 'R' was not declared in this scope 
 QString qHtml = R"(<button type="button">Click Me!</button>)";
 ^
- 
@ManiRon 
 Hi
 Code seems fine - so it must be compiler version.Is it an older Qt / Compiler ? Its a c++ 11 feature with R (raw strings) 
- 
@ManiRon 
 Hi
 Can you try to add
 CONFIG += c++11
 in your .pro file
 then run qmake and rebuild all (from menu) and see if it accepts it then.
- 
@ManiRon 
 Hi
 Can you try to add
 CONFIG += c++11
 in your .pro file
 then run qmake and rebuild all (from menu) and see if it accepts it then.- It worked sir
- But i am trying to create a button as you can see in the previous code its just displaying the text click me and not the button in the HTML file
- I know that in the list of attribute supported by QT <button> tag is not there whether we can make QT to make work on this
 
- 
- It worked sir
- But i am trying to create a button as you can see in the previous code its just displaying the text click me and not the button in the HTML file
- I know that in the list of attribute supported by QT <button> tag is not there whether we can make QT to make work on this
 @ManiRon 
 Hi
 Super. so was just c+11 support.
 The QT widgets cannot draw html Buttons so if you
 view them in textEdit/Browser no buttons can be shown.I know no easy way to have buttons, but you can try with 
 Qt WebEngine
 instead and see if it likes it.
- 
@ManiRon 
 Hi
 Super. so was just c+11 support.
 The QT widgets cannot draw html Buttons so if you
 view them in textEdit/Browser no buttons can be shown.I know no easy way to have buttons, but you can try with 
 Qt WebEngine
 instead and see if it likes it.
 


