Results 1 to 3 of 3

Thread: Qcombobox dinamically

  1. #1
    Join Date
    Jun 2015
    Posts
    28
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Qcombobox dinamically

    Greetings,

    in python i used to set the QComboBox data and get part from my SQL using dictionaries, just like the code below:
    Qt Code:
    1. // create a dict as a object, with this format: 'combobox.currentText':'table.field'
    2. tcDic={'ID':'customer.id','Name':'customer.name', 'Phone':'customer.phone'}
    3.  
    4. // add these keys in combobox: ID, Name, Phone
    5. combobox.addItems(tcDic.keys())
    6.  
    7. // in my custom sql, get dinamically the table field in the tcDic related with combobox.currentText
    8. cur.execute("SELECT cutomer.id, customer.name, customer.phone FROM customer WHERE " + tcDic[str(self.combobox.currentText())] + "LIKE % " + str(lineedit.text() + " %")
    To copy to clipboard, switch view to plain text mode 

    this way for me was simple and now i need to do something like that in C++. Someone would know if there a similar way or another way to do this kind of implementation?

    observation: I know to reference objects straight in SQL is not recomended. I done this only for simplify this example

    Best Regards!
    Juliano

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qcombobox dinamically

    You can use a QHash<QString, QString> as the dict

    Qt Code:
    1. QHash<QString, QQString> tcDict;
    2. tcDict["ID"] = "customer.id";
    3.  
    4. cur.execute("SELECT cutomer.id, customer.name, customer.phone FROM customer WHERE " + tcDict[comboBox->currentText()] ....
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  3. #3
    Join Date
    Jun 2015
    Posts
    28
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Qcombobox dinamically

    Quote Originally Posted by anda_skoa View Post
    You can use a QHash<QString, QString> as the dict

    Qt Code:
    1. QHash<QString, QQString> tcDict;
    2. tcDict["ID"] = "customer.id";
    3.  
    4. cur.execute("SELECT cutomer.id, customer.name, customer.phone FROM customer WHERE " + tcDict[comboBox->currentText()] ....
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

    Perfect!
    Thank you very much

Similar Threads

  1. Replies: 4
    Last Post: 31st October 2011, 13:01
  2. Replies: 0
    Last Post: 9th March 2011, 14:39
  3. Error loading plugin dinamically
    By Zero in forum Qt Programming
    Replies: 2
    Last Post: 24th January 2010, 00:31
  4. dinamically create widgets
    By msmihai in forum Newbie
    Replies: 7
    Last Post: 24th December 2008, 19:46
  5. How to dinamically change the type of a QCheckListItem
    By kalos80 in forum Qt Programming
    Replies: 4
    Last Post: 12th March 2007, 16:25

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.