Results 1 to 5 of 5

Thread: conversion problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2006
    Posts
    849
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    6
    Thanked 163 Times in 151 Posts

    Default Re: conversion problem

    while that fix might compile, it is wrong.

    try

    Qt Code:
    1. void checkpos(char cmd[3])
    2. {
    3. int count=0;
    4. int move[5]; // why an array? this code never can parse more than one...
    5. const char *tmp;
    6. for(int i=0;i<3;++i)
    7. if (cmd[i]==',')
    8. {
    9. tmp=&cmd[i+1];
    10. move[count++]=atoi(tmp);
    11. // and now? break? cmd can not contain further moves....
    12. // what about the (skipped) 'x'?
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 

    Note that char cmd[3] is quite a limitation and prevents you from parsing stuff like "15,x"

  2. #2
    Join Date
    Jan 2010
    Posts
    73
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    6
    Thanked 8 Times in 8 Posts

    Default Re: conversion problem

    I would be inclined to not worry about such low level processing and simply pass strings around. Something more like this:
    Qt Code:
    1. void simpleRegEx(const QString& s)
    2. {
    3. QRegExp regExp("(\\d+)\\s*,\\s*(\\S+)");
    4. if (regExp.indexIn(s) >= 0)
    5. {
    6. qDebug(qPrintable(QString("Number = %1").arg(regExp.cap(1).toLong())));
    7. qDebug(qPrintable(QString("Command = %1").arg(regExp.cap(2))));
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2010
    Posts
    63
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: conversion problem

    Thanks all. The problem has been solved.

Similar Threads

  1. Replies: 2
    Last Post: 20th October 2008, 18:34
  2. wchar to T50 conversion
    By rajveer in forum General Programming
    Replies: 1
    Last Post: 29th August 2008, 13:32
  3. RGBComponents / QImage Conversion problem
    By sincnarf in forum Qt Programming
    Replies: 2
    Last Post: 30th July 2007, 23:41
  4. Reg - Conversion of Qt3 to Qt4
    By suresh in forum Qt Programming
    Replies: 10
    Last Post: 28th August 2006, 23:10
  5. conversion of color
    By Stephano in forum Qt Programming
    Replies: 5
    Last Post: 22nd May 2006, 11:56

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
  •  
Qt is a trademark of The Qt Company.