Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Additional parameters für QObject class?

Additional parameters für QObject class?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    syfy323
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      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;
      }
      @

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • S Offline
        S Offline
        syfy323
        wrote on last edited by
        #3

        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.aspx

        I am currently integrating some Win32 API functions in my app.

        Thanks for your help, my class is now working! ;-)

        1 Reply Last reply
        0
        • K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          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_literal

          Since 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.

          Vote the answer(s) that helped you to solve your issue(s)

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved