Results 1 to 2 of 2

Thread: Converting DB to code

  1. #1
    Join Date
    Jun 2011
    Thanked 4 Times in 3 Posts
    Qt products
    MacOS X Windows

    Default Converting DB to code

    Hi guys,

    I'm trying to use values in my database as arguments for functions e.g. I have a column with colours e.g. red, blue etc and I would like to use these values as arguments into a function.

    In my header file, I've got #define red 7 etc etc, however the only way that I can think of using the database values would be a conversion function such as:

    Qt Code:
    1. int MyClass::Conversion(QString sDatabaseColumnText)
    2. {
    3. switch(sDatabaseColumnText)
    4. case "red":
    5. {
    6. return 7;
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 

    and then my function would just have:

    Qt Code:
    1. function(Conversion(query.value(0).toString();
    To copy to clipboard, switch view to plain text mode 

    I haven't compiled the code so I'm not sure if there are syntax errors, but it's the ideas that I'm more interested in.

    I obviously don't want to create a table in my database whereby I have an 'int' value assigned to my values, because this will double up my #defines and it's prone to errors and becomes an updating nightmare.

    EDIT P.S. I just remembered that cases can only use ints so my use of strings won't work, but anyway, imagine that I change my example to a bunch of 'if' statements.

  2. #2
    Join Date
    Mar 2011
    Hyderabad, India
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    MacOS X Unix/X11 Windows
    Wiki edits

    Default Re: Converting DB to code

    This is tipical case to use map<int, string>
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. Converting UIC 2 .h & .Cpp
    By jibolso in forum Newbie
    Replies: 5
    Last Post: 5th September 2009, 13:28
  2. Converting a php program to Qt
    By srohit24 in forum Qt Programming
    Replies: 7
    Last Post: 19th March 2009, 19:33
  3. Converting C++ to Qt4
    By ComaWhite in forum Qt Programming
    Replies: 8
    Last Post: 11th July 2008, 08:33
  4. Converting QT 4 to VC++
    By vvbkumar in forum Qt Programming
    Replies: 3
    Last Post: 22nd June 2006, 13:54
  5. Converting my UI to Qt4
    By Honestmath in forum Qt Programming
    Replies: 1
    Last Post: 14th April 2006, 23:58


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.