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. Indirection requires pointer operand
Forum Updated to NodeBB v4.3 + New Features

Indirection requires pointer operand

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 6.0k 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.
  • C Offline
    C Offline
    Caio.Sousa
    wrote on 18 Oct 2018, 00:59 last edited by
    #1

    Hi Guys,

    I need Help.
    I'm getting the error "indirection requires pointer operand (" QTextStream "invalid).Why?
    Thanks

    void menupainel::on_btnConfirmar_clicked()
    {
        Pessoa *p=new Pessoa();
    
    
        QDate Mydate =ui->dateNasc->date();
        QString date = Mydate.toString();
    
        QString nome = ui->txtNome->text();
        QString idade = ui->txtIdade->text();
        QString sexo = ui->comboSexo->currentText();
        QString rg = ui->txtRG->text();
        QString email = ui->txtEmail->text();
        QString cidade = ui->txtCity->text();
        QString estado = ui->txtEstado->text();
        QString telefone = ui->txtTelefone->text();
        QString celular = ui->txtCel->text();
    
        p->setNome(nome.toStdString());
        p->setIdade(idade.toStdString());
        p->setSexo(sexo.toStdString());
        p->setRG(rg.toStdString());
        p->setData(date.toStdString());
        p->setEstado(estado.toStdString());
        p->setTelefone(telefone.toStdString());
        p->setCelular(celular.toStdString());
        p->setEmail(email.toStdString());
    
    
    
        QFile file("text.txt");
    
            if(!file.open(QIODevice::Append|QIODevice::Text))
                return;
    
            QTextStream out(&file);
            *out<<p->getNome()<<endl;
    
    
        using namespace std;
    
        ui->stackedWidget->setCurrentIndex(2);
    }
    
    V 1 Reply Last reply 18 Oct 2018, 11:49
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 18 Oct 2018, 04:31 last edited by
      #2

      @Caio.Sousa said in Indirection requires pointer operand:

      *out<<p->getNome()<<endl;

      out is already an Object here, no need to dereference it again
      And it's also not needed to create Pessoa on the heap here. You even forgot to delete it and created a memory leak.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      6
      • C Offline
        C Offline
        Caio.Sousa
        wrote on 18 Oct 2018, 11:45 last edited by
        #3

        So would it look like? I'm new to C ++ and QT

        1 Reply Last reply
        0
        • C Caio.Sousa
          18 Oct 2018, 00:59

          Hi Guys,

          I need Help.
          I'm getting the error "indirection requires pointer operand (" QTextStream "invalid).Why?
          Thanks

          void menupainel::on_btnConfirmar_clicked()
          {
              Pessoa *p=new Pessoa();
          
          
              QDate Mydate =ui->dateNasc->date();
              QString date = Mydate.toString();
          
              QString nome = ui->txtNome->text();
              QString idade = ui->txtIdade->text();
              QString sexo = ui->comboSexo->currentText();
              QString rg = ui->txtRG->text();
              QString email = ui->txtEmail->text();
              QString cidade = ui->txtCity->text();
              QString estado = ui->txtEstado->text();
              QString telefone = ui->txtTelefone->text();
              QString celular = ui->txtCel->text();
          
              p->setNome(nome.toStdString());
              p->setIdade(idade.toStdString());
              p->setSexo(sexo.toStdString());
              p->setRG(rg.toStdString());
              p->setData(date.toStdString());
              p->setEstado(estado.toStdString());
              p->setTelefone(telefone.toStdString());
              p->setCelular(celular.toStdString());
              p->setEmail(email.toStdString());
          
          
          
              QFile file("text.txt");
          
                  if(!file.open(QIODevice::Append|QIODevice::Text))
                      return;
          
                  QTextStream out(&file);
                  *out<<p->getNome()<<endl;
          
          
              using namespace std;
          
              ui->stackedWidget->setCurrentIndex(2);
          }
          
          V Offline
          V Offline
          VRonin
          wrote on 18 Oct 2018, 11:49 last edited by VRonin
          #4
          • *out<<p->getNome()<<endl; becomes out<<p->getNome()<<endl;
          • remove using namespace std;
          • replace Pessoa *p=new Pessoa(); with auto p = std::make_unique<Pessoa>(); (requires #include <memory>)

          "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
          6
          • C Offline
            C Offline
            Caio.Sousa
            wrote on 18 Oct 2018, 12:13 last edited by
            #5

            @VRonin said in Indirection requires pointer operand:

            make_unique

            Ok, I'll try, but removing the * out to out gave me a problem talking about the QString, when I put the QString variable it works normal

            M 1 Reply Last reply 18 Oct 2018, 14:41
            0
            • C Caio.Sousa
              18 Oct 2018, 12:13

              @VRonin said in Indirection requires pointer operand:

              make_unique

              Ok, I'll try, but removing the * out to out gave me a problem talking about the QString, when I put the QString variable it works normal

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 18 Oct 2018, 14:41 last edited by
              #6

              @Caio.Sousa
              Hi
              Are you using std::string ?

              QTextStream out(&file);
              out<<p->getNome()<<endl;

              QTextStream dont like std::string as far as i know
              and it seems p->getNome() returns a std::string ?
              Any reason why its not QStrings in Pessoa ?

              C 1 Reply Last reply 18 Oct 2018, 19:55
              2
              • M mrjj
                18 Oct 2018, 14:41

                @Caio.Sousa
                Hi
                Are you using std::string ?

                QTextStream out(&file);
                out<<p->getNome()<<endl;

                QTextStream dont like std::string as far as i know
                and it seems p->getNome() returns a std::string ?
                Any reason why its not QStrings in Pessoa ?

                C Offline
                C Offline
                Caio.Sousa
                wrote on 18 Oct 2018, 19:55 last edited by
                #7

                @mrjj

                I did this:

                Dou um QString nome = ui->txtNome->text();
                p.setNome(nome.toStdString());

                there in the file I try to use the out<<p.getNome();

                Only then the error appears = "invalid operands to binary expression('QTextStream' and 'std::........'"

                M 1 Reply Last reply 18 Oct 2018, 22:34
                0
                • C Caio.Sousa
                  18 Oct 2018, 19:55

                  @mrjj

                  I did this:

                  Dou um QString nome = ui->txtNome->text();
                  p.setNome(nome.toStdString());

                  there in the file I try to use the out<<p.getNome();

                  Only then the error appears = "invalid operands to binary expression('QTextStream' and 'std::........'"

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 18 Oct 2018, 22:34 last edited by
                  #8

                  Hi
                  I was wondering if you need
                  std::string ?
                  If you change to QString, it will just work.

                  1 Reply Last reply
                  4

                  1/8

                  18 Oct 2018, 00:59

                  • Login

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