Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. QString appendText,,,,
Forum Updated to NodeBB v4.3 + New Features

QString appendText,,,,

Scheduled Pinned Locked Moved Unsolved C++ Gurus
4 Posts 3 Posters 587 Views 2 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.
  • A Offline
    A Offline
    Anonymous_Banned275
    wrote on last edited by
    #1

    As always , I am not sure where to post this .

    I am not sure how exactly this snippet works...the syntax is unfamiliar
    But it gives a local result (QEditText) when it runs "class variable " QProcess - proc.

    What I need is to have "appendText" as common , class variable, so it can
    be reused by other class .

    QString appendText(proc->readAll()); // slot ???
    ui->textEdit_3->append(appendText); // just display all - works fine

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

      Hi
      When you say "common , class variable, so it can
      be reused by other class ."

      Do you mean many instances of the same class SHARE this text or that these classes can ask some class about it and its sort of the text holder ?

      A 1 Reply Last reply
      0
      • mrjjM mrjj

        Hi
        When you say "common , class variable, so it can
        be reused by other class ."

        Do you mean many instances of the same class SHARE this text or that these classes can ask some class about it and its sort of the text holder ?

        A Offline
        A Offline
        Anonymous_Banned275
        wrote on last edited by
        #3

        @mrjj Whna I met was - the QString variable "appendText" is local to the function. .
        I like to have it as class variable / member .

        Actually I like to know /have explanation about the syntax

        • to me it looks as "function call of function appendText

        It is not that important, I found a workaround to do same - return a text / QStiing .
        Thanks

        JonBJ 1 Reply Last reply
        0
        • A Anonymous_Banned275

          @mrjj Whna I met was - the QString variable "appendText" is local to the function. .
          I like to have it as class variable / member .

          Actually I like to know /have explanation about the syntax

          • to me it looks as "function call of function appendText

          It is not that important, I found a workaround to do same - return a text / QStiing .
          Thanks

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @AnneRanch said in QString appendText,,,,:

          Actually I like to know /have explanation about the syntax

          to me it looks as "function call of function appendTe

          QString appendText(proc->readAll()); 
          

          Yes In C this would not be allowed. In C++ when declaring a class (QString here) variable we can create/initialize it with a value, in parentheses (among other ways). This actually uses the constructor at https://doc.qt.io/qt-6/qstring.html#QString-9, you could use any of the others (there are 10 of them!) listed there. That's why it's ( ... ): It calls your proc->readAll() and sets the variable to that.

          1 Reply Last reply
          2

          • Login

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