Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QStringList: cannot define QStringList
QtWS25 Last Chance

QStringList: cannot define QStringList

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 4.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    webmaster.skelton
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tony
      wrote on last edited by
      #2

      (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.

      1 Reply Last reply
      0
      • W Offline
        W Offline
        webmaster.skelton
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • ? This user is from outside of this forum
          ? This user is from outside of this forum
          Guest
          wrote on last edited by
          #4

          [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

          1 Reply Last reply
          0
          • G Offline
            G Offline
            giesbert
            wrote on last edited by
            #5

            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....

            Nokia Certified Qt Specialist.
            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

            1 Reply Last reply
            0
            • W Offline
              W Offline
              webmaster.skelton
              wrote on last edited by
              #6

              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)

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved