0

I was playing with QT and I found a small issue. (I am really new in Qt). After search about that, I did not find anything. The problem is: In header file:

#include <QMainWindow>
    namespace Ui {
class jAudio;
}

class jAudio : public QMainWindow
{
    Q_OBJECT

public:
    explicit jAudio(QWidget *parent = 0);

    ~jAudio();

private:
    Ui::jAudio *ui;

private slots:
    void jSetup (void);
    void jInfo (QString);
    void jFillComboBox(QComboBox, QStringList);
    void on_bRecord_clicked();
};

And I declare the method in .cpp file like:

#include "jaudio.h" 
#include "ui_jaudio.h"
void jAudio::jFillComboBox(QComboBox comboBox, QStringList data){
    for (int i = 0;  i< options.count(); i++){
        comboBox->addItem(data[i],i);
    }
}

When I try to run the code then the error appear:

..../jAudio/jaudio.h:25: error: 
‘QComboBox’ has not been declared
 void jFillComboBox(QComboBox, QStringList);

Do you know what am I doing wrong?

Thnak you very much!!

  • I don't see any includes in your header nor source file – quinz Nov 05 '17 at 21:19
  • And you maybe as new in C++ as in Qt. Not only no includes, you are not supposed to pass any arbitrary object by value without knowing that that would work. `QComboBox` should be passed as a pointer or `QComboBox*`. – Alexander V Nov 05 '17 at 21:22
  • Hi. I just notice I did not copy that includes in the question. In the header file, there is only one include: "#include " and in .cpp file are two: #include "jaudio.h" #include "ui_jaudio.h" – Javier Gonzalez Moncayo Nov 05 '17 at 21:33
  • @JavierGonzalezMoncayo Change `void jFillComboBox(QComboBox, QStringList);` to `void jFillComboBox(QComboBox *, QStringList);` and `void jAudio::jFillComboBox(QComboBox* comboBox, QStringList data)`. – eyllanesc Nov 05 '17 at 22:42
  • @eyllanesc, I tried your solution but still happening the same error..... Do you have any idea about what is happening? – Javier Gonzalez Moncayo Nov 06 '17 at 18:04
  • Share your code through github or gist and I will help you solve it. – eyllanesc Nov 06 '17 at 18:05
  • Here we go: https://github.com/JavierMoncayo/jAudio . The file involve are: "jaudio.h" and "jaudio.cpp". Thank you very much. You are the best. – Javier Gonzalez Moncayo Nov 06 '17 at 18:17

1 Answers1

0

In jAudio.h: add #include <QComboBox> and #include <QStringList>. And change jFillComboBox to jFillComboBox(QComboBox*, QStringList), as previously mentioned in comments. The reasoning for the second part is that QComboBox is derived from QWidget, and QWidget objects cannot be copied. If you've come from other, higher-level languages, the concept of non-copyable objects and passing-by-pointer (or reference) may be foreign to you. If that's the case, consider looking through this question and the links there.

Jamie S
  • 111
  • 1
  • 10