Results 1 to 3 of 3

Thread: converting of string to enum

  1. #1
    Join Date
    Sep 2007
    Posts
    83
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default converting of string to enum

    Hi
    I am using QextSerialPort class.with my application i am going to configure the port settings of my pc.
    to achieve the above tasks i collect the port setting parameters from my gui combo boxes(which are string type) and i converted "string" parameters to "enum" type using below expression

    Qt Code:
    1. QString portdbs=ui.comboBox_3->currentText();
    2. portdbs=portdbs.prepend("DATA_");
    3. DataBitsType dbs=(DataBitsType)Enum.Parse(typeof(DataBitsType), portdbs,true);
    4. port->setDataBits(dbs);
    To copy to clipboard, switch view to plain text mode 
    after this i compiled my application,but am getting below error:

    main.cpp:2381: error: `Enum' undeclared (first use this function)
    main.cpp:2381: error: (Each undeclared identifier is reported only once for each
    function it appears in.)
    main.cpp:2381: error: expected primary-expression before ')' token
    main.cpp:2381: error: expected `,' or `;' before "Enum"
    For avoiding that error i added "using System;" to my application,but surprisingly my edit plus editor is not detecting the "using"keyword(i.e the color is not changing)

    please help me on this issue.

    Thanks alot to all,
    Last edited by jpn; 24th October 2008 at 16:31. Reason: missing [code] tags

  2. #2
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: converting of string to enum

    Are these your own enums? Or enums in QextSerialPort? In any case there are different ways you can approach this.

    For one, you could use setItemData() on your QComboBox items, and store the int value of the enum there, then call itemData() to retrieve it.

    Or if you didn't want to do that, you could create a map with the string as the key and the enum int as the value...etc.

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: converting of string to enum

    Quote Originally Posted by jjbabu View Post
    Qt Code:
    1. DataBitsType dbs=(DataBitsType)Enum.Parse(typeof(DataBitsType), portdbs,true);
    To copy to clipboard, switch view to plain text mode 
    What? Are you trying to mix C# and C++?

    See Q_ENUMS() and QMetaEnum.
    J-P Nurmi

Similar Threads

  1. saving a c string of variable length in a shared memory?
    By nass in forum General Programming
    Replies: 4
    Last Post: 3rd January 2007, 14:40
  2. Converting number to string.
    By safknw in forum Newbie
    Replies: 2
    Last Post: 18th September 2006, 12:12
  3. enum property
    By illuzioner in forum Qt Tools
    Replies: 10
    Last Post: 22nd August 2006, 21:47
  4. converting string to unsigned integer
    By mgurbuz in forum Qt Programming
    Replies: 4
    Last Post: 12th May 2006, 09:46

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.