LetTheWritersWrite
LetTheWritersWrite

Reputation: 99

Adding parameters to Q_Object constructor

When I create a new Q_OBJECT class in Qt Creator, it makes this default constructor. I want to add another parameter so that I can pass user input but I'm not sure how to do this since QObject is the first parameter and have no idea how to skip the first parameter and pass the user input on the QString userInput parameter.

How to take this default:

public:
            explicit renderJob(QObject *parent = 0);

To do this

public:
    explicit renderJob(QObject *parent = 0,QString userInput);

Upvotes: 4

Views: 5220

Answers (1)

eyllanesc
eyllanesc

Reputation: 243887

In C++ if you put default parameters these should be in the last positions. In addition, the QObject parameter should be passed to the base class constructor. For example:

class renderJob: public {BaseObjectClass}
{
    Q_OBJECT
public:
    explicit renderJob(QString userInput, QObject *parent = 0);
}

[...]

renderJob::renderJob(QString userInput, QObject *parent):
{BaseObjectClass}(parent)
{
    [...]
}

Upvotes: 6

Related Questions