Results 1 to 4 of 4

Thread: Accessing QVariant of QComboBox

  1. #1
    Join Date
    Nov 2009
    Posts
    11
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Accessing QVariant of QComboBox

    I'm wanting to use a QComboBox as a sort of data storage for my application. It's not a large ammount of data, and I think this would be the easiest way to not be constantly reading from the database file. This little snippit shows what I'm trying to do.

    Qt Code:
    1. QStringList dataList;
    2.  
    3. dataList << "D1" << "D2" << "D3";
    4.  
    5. ui->ShowDate->insertItem(0, QDate(query.value(2).toInt(), query.value(0).toInt(),
    6. query.value(1).toInt()).toString(("MMMM d, yyyy")), dataList);
    To copy to clipboard, switch view to plain text mode 

    I know how to access the text with

    Qt Code:
    1. ui->lineEdit->setText(ui->ShowDate->currentText());
    To copy to clipboard, switch view to plain text mode 

    but how do I access the QVariant?

    I'm new to not only Qt, but c++ as well, so a small snippit showing how to put, say dataList[0] into a lable...

    Qt Code:
    1. ui->label->setText(<however to get dataList[0] in here>);
    To copy to clipboard, switch view to plain text mode 

    Qt version 4.5

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Accessing QVariant of QComboBox

    I know how to access the text with
    Qt Code:
    1
    ui->lineEdit->setText(ui->ShowDate->currentText());
    but how do I access the QVariant?
    I dont think QLineEdit has QVariant...

    I'm new to not only Qt, but c++ as well, so a small snippit showing how to put, say dataList[0] into a lable...
    ui->label->setText(dataList.at(0));

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Accessing QVariant of QComboBox

    QComboBox::itemData().

    You can also use "dynamic properties" on every widget.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. The following user says thank you to wysota for this useful post:

    lnxusr (9th November 2009)

  5. #4
    Join Date
    Nov 2009
    Posts
    11
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Accessing QVariant of QComboBox

    @aamer4yu: I think you misunderstood my question. The QVariant I was talking about was attached to my QComboBox. I was trying to get that data into the lineEdit and/or label.

    @wysota: Thank you so much. Looking into the QComboBox::itemData() and Qt::UserRole got me access to data... and no code snippit needed, I used your info to discover how to do it on my own.

    You have been officially thanked..

Similar Threads

  1. Convert between a custom data type wrapped in a QVariant
    By darkadept in forum Qt Programming
    Replies: 2
    Last Post: 17th March 2009, 09:07
  2. Getting Microsoft Word Object to SaveAs
    By jvwebb in forum Newbie
    Replies: 3
    Last Post: 2nd September 2008, 19:27
  3. QComboBox drop list button events
    By maird in forum Qt Programming
    Replies: 5
    Last Post: 20th October 2007, 19:25
  4. using QComboBox as an ItemView
    By EricTheFruitbat in forum Qt Programming
    Replies: 3
    Last Post: 24th January 2007, 16:14
  5. Crash caused by QVariant (mis)use
    By mclark in forum Newbie
    Replies: 2
    Last Post: 31st October 2006, 15:05

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.