QStringList: cannot define QStringList



  • I am working on a factory..... Well its better to just to show the code:

    QComboBox* ComboBoxFactory::createComboBox_MedicationType(QString id,QString styleSheet,QStringList list)

    and then i want to call it:

    FrameFactory::gridLayout->addWidget(ComboBoxFactory::GetInstance()->createComboBox_MedicationType("ComboBox",".QComboBox{};",list defined here),2,0,1,2,Qt::AlignAbsolute| Qt::AlignTop);

    The problem is i cant figure out how to define the list within addwidget can i Do it this way and if so what is the syntax for it?

    thanks



  • (ComboBoxFactory::GetInstance()->createComboBox_MedicationType(“ComboBox”,”.QComboBox{};”,QStringList() << "A" << "B", ...

    Anyway, if you have many items, better create a QStringList aside, it's more readable.

    Btw, please define your factory in this way:

    QComboBox* ComboBoxFactory::createComboBox_MedicationType(const QString &id, const QString &styleSheet, const QStringList &list)

    it's more efficient to pass by const-by-reference. The reason is written in every C++ book :)

    T.



  • Thanks for the post, that solved my issues. I am relatively new to QT and Don't have it all down yet.



  • [quote author="webmaster.skelton" date="1290020788"]Thanks for the post, that solved my issues. I am relatively new to QT and Don't have it all down yet.[/quote]

    webmaster, just a small note, its Qt and not QT (quick time), also better to enclose code in @ tag for better readability



  • You should also add the parent parameter to your function like this:

    @
    QComboBox* ComboBoxFactory::createComboBox_MedicationType(const QString &id, const QString &styleSheet, const QStringList &list, QWidget* parent);
    @
    Or is it a member of your class? I don't think so (as its a factory). If you don't add the parent, you always create top level widgets and have to reparent them afterwards....



  • I had not thought of that Gerolf, Thank you for pointing that out( still not used to the parent and child aspect of Qt yet) I typically do not use a designer of any sort and create custom objects in pure C++( using Eclipse)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.