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
QtWS25 Last Chance

Indirection requires pointer operand

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 5.9k 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.
  • C Offline
    C Offline
    Caio.Sousa
    wrote on 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);
    }
    
    VRoninV 1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 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 last edited by
        #3

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

        1 Reply Last reply
        0
        • C Caio.Sousa

          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);
          }
          
          VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on 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 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

            mrjjM 1 Reply Last reply
            0
            • C Caio.Sousa

              @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

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on 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
              2
              • mrjjM mrjj

                @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 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::........'"

                mrjjM 1 Reply Last reply
                0
                • C Caio.Sousa

                  @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::........'"

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 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

                  • Login

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