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. C++ class member declaration
QtWS25 Last Chance

C++ class member declaration

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 5 Posters 1.8k Views
  • 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.
  • Dan3460D Offline
    Dan3460D Offline
    Dan3460
    wrote on last edited by
    #1

    I found this member declaration on a sample code, I don't understand the ";" on the parameters passed to the function.
    bool DbManager::addPerson(const QString& name)
    {
    bool success = false;
    // you should check if args are ok first...
    QSqlQuery query;
    query.prepare("INSERT INTO people (name) VALUES (:name)");
    query.bindValue(":name", name);
    if(query.exec())
    {
    success = true;
    }
    else
    {
    qDebug() << "addPerson error: "
    << query.lastError();
    }

    return success;
    }

    1 Reply Last reply
    0
    • jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Dan3460
      Which ";" do you mean?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        If you mean the : before name it's to give your binding a name. It's explained here.

        You could be using another name for that variable if you wanted. Using the same just makes it clearer that you are going to put a value in the name column using a binding that is also called name.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1
        • Dan3460D Offline
          Dan3460D Offline
          Dan3460
          wrote on last edited by
          #4

          Sorry, I should have looked at my copy before I posted.
          The code that i got said something like:
          bool DbManager::addPerson(const QString& instring; name)
          that ";" before name tripped me off. Now I cannot find the original post, or it was changed.
          Does that ";" makes any sense on a function implementation?

          VRoninV 1 Reply Last reply
          0
          • Dan3460D Dan3460

            Sorry, I should have looked at my copy before I posted.
            The code that i got said something like:
            bool DbManager::addPerson(const QString& instring; name)
            that ";" before name tripped me off. Now I cannot find the original post, or it was changed.
            Does that ";" makes any sense on a function implementation?

            VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #5

            @Dan3460 No, that declaration is invalid in C++

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            1 Reply Last reply
            0
            • Chris KawaC Online
              Chris KawaC Online
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by
              #6

              It's probably a typo of some sort, but I'm feeling playful today, so I'll say it's not invalid c++. See below ;)

              #define instring )
              #define foo()
              #define name foo(
              
              bool DbManager::addPerson(const QString& instring; name)
              

              Perfectly valid c++ :) Note that MSVC will complain because its macro expansion is fundamentally broken.

              1 Reply Last reply
              0
              • Dan3460D Offline
                Dan3460D Offline
                Dan3460
                wrote on last edited by
                #7

                Thanks Sirs, that is what I thought.

                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