Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding parameters to Q_Object constructor

Tags:

c++

qt

qt5

qobject

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);
like image 432
LetTheWritersWrite Avatar asked Oct 20 '25 01:10

LetTheWritersWrite


1 Answers

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)
{
    [...]
}
like image 187
eyllanesc Avatar answered Oct 21 '25 14:10

eyllanesc