Results 1 to 2 of 2

Thread: chop String if more then 2 spaces are found

  1. #1
    Join Date
    Apr 2020
    Posts
    14
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default chop String if more then 2 spaces are found

    Hi,

    iI found out how to read something from stdout, Thx for the help.

    Now i got my lines in a listview which works pretty well, but I Just need the first chracaters found in each line, as long as there is not more than 1 space.

    Output in app:

    Auswahl_015.jpg

    Output in terminal:

    Qt Code:
    1. ubuntu@Laptop:~$ /opt/bin/mediaclient --scandabservices /dev/dab0
    2. Service Name, Service ID, Component ID
    3. EPG Deutschland 0xe0d110bc 0xc024
    4. TPEG 0xe0d010bc 0xc023
    5. TPEG_MM 0xe0d310bc 0xc021
    6. Dlf 0xd210 0xa
    7. Dlf Kultur 0xd220 0xb
    8. Dlf Nova 0xd230 0xc
    9. DRadio DokDeb 0xd240 0xd
    10. Schwarzwaldradio 0x100d 0x7
    11. ENERGY 0x1a45 0x4
    12. SCHLAGERPARADIES 0x10c3 0x14
    13. Absolut relax 0x17fa 0x3
    14. RADIO BOB! 0x15dd 0x16
    15. KLASSIK RADIO 0xd75b 0x6
    16. sunshine live 0x15dc 0x15
    17. Radio Horeb 0xd01c 0x5
    18. ERF Plus 0x1a64 0x2
    19. DRadio Daten 0xe0d00250 0xc001
    To copy to clipboard, switch view to plain text mode 

    As you can see there is some kind of difference but it would be enough in the first step, to have only the service name displayed in the listview.

    The second step is to only read the first 6 characters of the service id, as this is needed for the next step, to tune to this service id.

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: chop String if more then 2 spaces are found

    Every time second column starts with 0x. So
    Qt Code:
    1. QString service_name = line.left(line.indexOf(QLatin1String("0x")));
    To copy to clipboard, switch view to plain text mode 
    P.S.
    Check if the separator is not tab.
    P.S.2.
    Qt Code:
    1. QStringList one_line = line.split('\t');
    To copy to clipboard, switch view to plain text mode 
    And you have a line divided into three elements.
    Last edited by Lesiok; 20th April 2020 at 14:16.

Similar Threads

  1. Remove all spaces in string except spaces in quotes
    By bnosam in forum Qt Programming
    Replies: 5
    Last Post: 26th June 2014, 03:37
  2. QTableWidget spaces between column
    By evergreen in forum Qt Programming
    Replies: 1
    Last Post: 12th May 2011, 10:27
  3. Spaces in QTextEdit
    By jgrauman in forum Qt Programming
    Replies: 2
    Last Post: 22nd June 2009, 18:28
  4. Spaces between lines in QTextEdit
    By troorl_ua in forum Qt Programming
    Replies: 1
    Last Post: 3rd July 2007, 00:06
  5. qmake INCLUDEPATH with spaces
    By bitChanger in forum Qt Programming
    Replies: 8
    Last Post: 28th April 2006, 05:39

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.