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. How to pass an attribut to an another class.

How to pass an attribut to an another class.

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 738 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.
  • yoyoY Offline
    yoyoY Offline
    yoyo
    wrote on last edited by
    #1

    Hello,
    I 'am trying to pass an attribut to another class but it doesn't working.
    Anybody's knows the good method ?
    In my mainwindow.cpp i catch a QString path (filepath_var) and i whant to pass it in window dialog in order to make a traitement on QFiles and display a chart.
    please help me.


    Mainwondows*********************************************************************


    void MainWindow::on_pushButton_Load_File_clicked()
    {
    QString Filter = "All files (.) ;; Text Files (*.txt)";
    QString filename = QFileDialog::getOpenFileName(this, "Ouvrir un fichier",QDir::homePath(), Filter);

    QFile File_R(filename);
    if (!File_R.open(QIODevice::ReadOnly | QIODevice::Text))
    
    {QMessageBox::information(this, "Pas de fichier selectionner", "Pas de fichier chargée !");}
    
    //else
    //{QMessageBox::information(this,tr("ouvert"),filename);}
    
    
    QFileInfo fi(filename);
    QString filename_aff = fi.fileName();
    
    QString filepath_var =(fi.filePath());
    
    ui->lineEdit_2->setText(filename_aff);
    

    }



    Graph_az_cons::Graph_az_cons(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Graph_az_cons)
    {
    ui->setupUi(this);

    QString filename = ("C:/Users/Documents/outil/reg.txt");
    QFile File_R(filename);
    if (!File_R(QIODevice::ReadOnly | QIODevice::Text))
    

    {QMessageBox::information(this, "Pas de fichier selectionner", "Pas de fichier chargée !");}

    QTextStream flux(&File_R);
    while(!flux.atEnd())

                    {
    
            QString line = flux.readLine();
    
    jsulmJ 1 Reply Last reply
    0
    • yoyoY yoyo

      Hello,
      I 'am trying to pass an attribut to another class but it doesn't working.
      Anybody's knows the good method ?
      In my mainwindow.cpp i catch a QString path (filepath_var) and i whant to pass it in window dialog in order to make a traitement on QFiles and display a chart.
      please help me.


      Mainwondows*********************************************************************


      void MainWindow::on_pushButton_Load_File_clicked()
      {
      QString Filter = "All files (.) ;; Text Files (*.txt)";
      QString filename = QFileDialog::getOpenFileName(this, "Ouvrir un fichier",QDir::homePath(), Filter);

      QFile File_R(filename);
      if (!File_R.open(QIODevice::ReadOnly | QIODevice::Text))
      
      {QMessageBox::information(this, "Pas de fichier selectionner", "Pas de fichier chargée !");}
      
      //else
      //{QMessageBox::information(this,tr("ouvert"),filename);}
      
      
      QFileInfo fi(filename);
      QString filename_aff = fi.fileName();
      
      QString filepath_var =(fi.filePath());
      
      ui->lineEdit_2->setText(filename_aff);
      

      }



      Graph_az_cons::Graph_az_cons(QWidget *parent) :
      QDialog(parent),
      ui(new Ui::Graph_az_cons)
      {
      ui->setupUi(this);

      QString filename = ("C:/Users/Documents/outil/reg.txt");
      QFile File_R(filename);
      if (!File_R(QIODevice::ReadOnly | QIODevice::Text))
      

      {QMessageBox::information(this, "Pas de fichier selectionner", "Pas de fichier chargée !");}

      QTextStream flux(&File_R);
      while(!flux.atEnd())

                      {
      
              QString line = flux.readLine();
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @yoyo There are many ways. If you want to pass it to a dialog then simply add it to dialogs constructor:

      Graph_az_cons::Graph_az_cons(QString fileName, QWidget *parent) :
      QDialog(parent),
      ui(new Ui::Graph_az_cons)
      {
      

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

      1 Reply Last reply
      2
      • yoyoY Offline
        yoyoY Offline
        yoyo
        wrote on last edited by
        #3

        Sorry but i tried, it is not working :

        I put

        Graph_az_cons(QString fileName, QWidget *parent) :

        in my graph_az_cons.cpp and my graph_az_cons.h

        but Qt return to me a error's message : no matching function for call to Graph_az_cons(MainWindow*)'

        Code in my main window to call my Qdialog is

        if (ui->checkBox_az_cons->isChecked())

            {
        
            graph_az_cons = new Graph_az_cons(this);
            graph_az_cons->show();
        
        
            }
        

        I don't known ??

        JonBJ 1 Reply Last reply
        0
        • yoyoY yoyo

          Sorry but i tried, it is not working :

          I put

          Graph_az_cons(QString fileName, QWidget *parent) :

          in my graph_az_cons.cpp and my graph_az_cons.h

          but Qt return to me a error's message : no matching function for call to Graph_az_cons(MainWindow*)'

          Code in my main window to call my Qdialog is

          if (ui->checkBox_az_cons->isChecked())

              {
          
              graph_az_cons = new Graph_az_cons(this);
              graph_az_cons->show();
          
          
              }
          

          I don't known ??

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

          @yoyo
          You took @jsulm 's suggestion of changing the dialog's constructor to:

          Graph_az_cons(QString fileName, QWidget *parent) :
          

          So it now accepts a file name string as its first parameter, right?

          So do you not think you need to change your call

          graph_az_cons = new Graph_az_cons(this);
          

          to actually pass whatever the file name is to the constructor from this line? That is the point of the change you are making.

          1 Reply Last reply
          1
          • yoyoY Offline
            yoyoY Offline
            yoyo
            wrote on last edited by
            #5

            Yess ! it's working

            I put in my Mainwindow

            if (ui->checkBox_az_cons->isChecked())

                {
            
                graph_az_cons = new Graph_az_cons(filepath_var,this);
                graph_az_cons->show();
            
                }
            

            in my graph_az_cons.h

            public:
            explicit Graph_az_cons( QString filename, QWidget *parent = nullptr);
            ~Graph_az_cons();

            and in my my graph_az_cons.cpp

            Graph_az_cons::Graph_az_cons(QString filename,QWidget *parent) :
            QDialog(parent),
            ui(new Ui::Graph_az_cons)
            {
            ui->setupUi(this);

            Pablo J. RoginaP 1 Reply Last reply
            1
            • yoyoY yoyo

              Yess ! it's working

              I put in my Mainwindow

              if (ui->checkBox_az_cons->isChecked())

                  {
              
                  graph_az_cons = new Graph_az_cons(filepath_var,this);
                  graph_az_cons->show();
              
                  }
              

              in my graph_az_cons.h

              public:
              explicit Graph_az_cons( QString filename, QWidget *parent = nullptr);
              ~Graph_az_cons();

              and in my my graph_az_cons.cpp

              Graph_az_cons::Graph_az_cons(QString filename,QWidget *parent) :
              QDialog(parent),
              ui(new Ui::Graph_az_cons)
              {
              ui->setupUi(this);

              Pablo J. RoginaP Offline
              Pablo J. RoginaP Offline
              Pablo J. Rogina
              wrote on last edited by
              #6

              @yoyo please don't forget to mark your post as solved!

              Upvote the answer(s) that helped you solve the issue
              Use "Topic Tools" button to mark your post as Solved
              Add screenshots via postimage.org
              Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

              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