tags:

views:

24

answers:

2

Hi I am trying to write a simple function where I load a text file to a QComboBox, I am very new to QT and C++. Here is what i have right now:

void frmVerification::openTextFile(QComboBox* qCombo, string filename) {
    using namespace std;
    string line;
    ifstream myfile(filename.c_str());
    if (myfile.is_open())
    {
      while (! myfile.eof() )
      {
        getline (myfile,line);
        qCombo.addItem(line, "0");
      }
      myfile.close();
    }
}

.. i get this complile time error

error: request for member 'addItem' in 'qCombo', which is of non-class type 'QComboBox*'

Any help would be great!

+2  A: 

qCombo is a pointer. You want to use: qCombo->addItem(line, "0");

Slavik81
A: 

Never Mind, the pass by reference wasn't the broken part, it was the file open. I fixed it. Thanks

if anyone is interest

void frmVerification::openTextFile(QComboBox* qCombo, QString fileName) {
    QFile file(fileName);
    if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
        QTextStream in(&file);
        QString line = in.readLine();
        while (!line.isNull()) {
            //process_line(line);
            line = in.readLine();
            qCombo->addItem(line, "0");
        }
    }
}
rizzo0917