Results 1 to 4 of 4

Thread: Capture text from changeable source (regex)

  1. #1
    Join Date
    Jun 2011
    Posts
    69
    Thanks
    13
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Question Capture text from changeable source (regex)

    Actually i couldn't find suitable title than this!
    Okay i have a QTextBrowser which get output from QProcess and the output printed-out from "axel" downloader.
    What i want to do is get just proggress text which is like [ #%]
    the output is here
    Qt Code:
    1. [ 0%] [0 ] [ 275.9KB/s] [ 2h06]
    2. [ 22%] [0 ] [ 276.4KB/s] [ 2h06]
    3. [ 34%] [0 ] [ 276.9KB/s] [ 2h06]
    4. [ 43%] [0 ] [ 278.9KB/s] [ 2h05]
    To copy to clipboard, switch view to plain text mode 
    in try some regex pattern which i was failed in them.
    • \\d%
    • \\d{1,3}%

    so if i can get the progress text then i can reach to download speed, remaining time and others i think.

    i just want to show the download progress on the gui, of course i can calculate the download progress by orignal file size and downloaded size, but get help from regex seems more clever
    Last edited by Alir3z4; 5th December 2011 at 06:09. Reason: updated contents
    ...یه مرد هیچوقت زمین نمیخوره

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Capture text from changeable source (regex)

    Please read the documentation to QRegExp. As a short kick-off
    Qt Code:
    1. QRegExp rx("\\[[ ]*([1-9]{1,2})\\%\\]");
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jun 2011
    Posts
    69
    Thanks
    13
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Capture text from changeable source (regex)

    Despite that yours didn't smash any stone for me :|, Well thanks who move this thread to Newbie sub-forum because it remind me that don't hack stupid soft sands when you can use API
    i just found axel's API.
    ...یه مرد هیچوقت زمین نمیخوره

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Capture text from changeable source (regex)

    Using the API of your downloader is surely the best way to go. As to my suggestion:
    Qt Code:
    1. QString test = "[ 34%] [0 ] [ 276.9KB/s] [ 2h06]";
    2. QRegExp rx("\\[[ ]*([1-9]{1,2})\\%\\]");
    3. rx.indexIn(test);
    4. qWarning() << rx.capturedTexts();
    To copy to clipboard, switch view to plain text mode 
    returns 34. The percentage you wanted... (At least I understand your post so.)

Similar Threads

  1. Replies: 3
    Last Post: 3rd March 2011, 00:22
  2. Looking for a mate for an open-source text editor
    By Utku in forum General Discussion
    Replies: 1
    Last Post: 7th November 2009, 21:42
  3. Replies: 3
    Last Post: 5th July 2009, 17:22
  4. Problem with regex
    By mikro in forum Newbie
    Replies: 4
    Last Post: 14th December 2006, 10:43
  5. need help with my regex
    By patcito in forum Qt Programming
    Replies: 1
    Last Post: 29th May 2006, 17:39

Tags for this Thread

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.