Additional parameters für QObject class?
-
This is a very basic question.
I have a class named HddAllocation:
@class HddAllocation : public QObject
{
Q_OBJECT
public:
explicit HddAllocation(QObject *parent = 0, const wchar_t * mountPoint = L"C:\");@
...Without >, const wchar_t * mountPoint = L"C:\"< I can create a new class easily. I just want to append a single parameter.
@HddAllocation::HddAllocation(QObject *parent, const wchar_t * mountPoint) :
QObject(parent)
{
lpDirectoryName = mountPoint;
lpFreeBytesAvailable = new ULARGE_INTEGER;
lpTotalNumberOfBytes = new ULARGE_INTEGER;
lpTotalNumberOfFreeBytes = new ULARGE_INTEGER;}@
Doing this forces me to provide a QObject parent. But how?
Thanks.
-
You can change the sequence of the parameters, if you do not want to provide an instance for the QObject.
@
class HddAllocation : public QObject
{
Q_OBJECT
public:
explicit HddAllocation(const wchar_t * mountPoint, QObject *parent = 0 );
@I have removed the default parameter. So you have to provide a parameter. I would assume that the compiler complained with your initialization of the default for mountPoint anyhow. At least I did not understand what the extra 'L' was for.
@
HddAllocation::HddAllocation(const wchar_t * mountPoint, QObject *parent ) :
QObject(parent)
{
lpDirectoryName = mountPoint;
lpFreeBytesAvailable = new ULARGE_INTEGER;
lpTotalNumberOfBytes = new ULARGE_INTEGER;
lpTotalNumberOfFreeBytes = new ULARGE_INTEGER;
}
@ -
Thanks! This is exactly what I needed.
The "L" in front of the string is for wide string literals, represented as L"xxx".
http://msdn.microsoft.com/en-us/library/69ze775t.aspxI am currently integrating some Win32 API functions in my app.
Thanks for your help, my class is now working! ;-)
-
Thanks that is explaining it. I typically stay with standard ASCII chars.
Here is also a "link from a more neutral source":http://en.cppreference.com/w/cpp/language/string_literalSince you are apparently learning C++ you might want to check also such information sources. MSDN has great detailed information which is really useful. However, out of personal experience I would recommend to do those checks. Otherwise you may face have trouble to migrate to other platforms without ms compiler.