QT C++ Passing Widgets to function
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开发者_StackOverflow社区 be great!
qCombo is a pointer. You want to use: qCombo->addItem(line, "0");
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");
}
}
}
精彩评论