Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to pass parameter (pointer) to function ?

How to pass parameter (pointer) to function ?

Scheduled Pinned Locked Moved C / C++ / MFC
debuggingquestiondesignhelptutorial
6 Posts 3 Posters 27 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    What is a correct way to pass parameter / variable to function ? The attached snippet writes text to the GUI object and it is done in object constructor. My task is to pass ui->textEdit_2 to object function so it can be processed OUTSIDE constructor

    ui->setupUi(this);

    text = "Constructor ";
    ui->textEdit\_2->append(text);
    
    text = " Initialize DEBUG trace ";
    ui->textEdit\_2->append(text);
    

    private:
    public:
    Ui::MainWindow_C_CODE_FORM *ui;

    Here is my test function declaration: QString ShowText(QString text, QTextEdit *textEDIT ); I have tried several ways to access the function, but I am obviously "doing it wrong". PS I you cannot help "as is " , please, do not complain - it would work better if you ask what is missing instead. Thank you very much .

    K CPalliniC L 3 Replies Last reply
    0
    • L Lost User

      What is a correct way to pass parameter / variable to function ? The attached snippet writes text to the GUI object and it is done in object constructor. My task is to pass ui->textEdit_2 to object function so it can be processed OUTSIDE constructor

      ui->setupUi(this);

      text = "Constructor ";
      ui->textEdit\_2->append(text);
      
      text = " Initialize DEBUG trace ";
      ui->textEdit\_2->append(text);
      

      private:
      public:
      Ui::MainWindow_C_CODE_FORM *ui;

      Here is my test function declaration: QString ShowText(QString text, QTextEdit *textEDIT ); I have tried several ways to access the function, but I am obviously "doing it wrong". PS I you cannot help "as is " , please, do not complain - it would work better if you ask what is missing instead. Thank you very much .

      K Offline
      K Offline
      k5054
      wrote on last edited by
      #2

      Please supply the types of your objects, a sample of how you are calling ShowText() and an explanation of why you thing you're "doing it wrong". Do you get compilation errors or warnings? Does the program crash, or do something unexpected? Does the fan in the bedroom turn on? You're not telling us, and most of us will refuse to speculate.

      Keep Calm and Carry On

      1 Reply Last reply
      0
      • L Lost User

        What is a correct way to pass parameter / variable to function ? The attached snippet writes text to the GUI object and it is done in object constructor. My task is to pass ui->textEdit_2 to object function so it can be processed OUTSIDE constructor

        ui->setupUi(this);

        text = "Constructor ";
        ui->textEdit\_2->append(text);
        
        text = " Initialize DEBUG trace ";
        ui->textEdit\_2->append(text);
        

        private:
        public:
        Ui::MainWindow_C_CODE_FORM *ui;

        Here is my test function declaration: QString ShowText(QString text, QTextEdit *textEDIT ); I have tried several ways to access the function, but I am obviously "doing it wrong". PS I you cannot help "as is " , please, do not complain - it would work better if you ask what is missing instead. Thank you very much .

        CPalliniC Offline
        CPalliniC Offline
        CPallini
        wrote on last edited by
        #3

        Something like

        void ShowText(QString text, QTextEdit * pTextEdit)
        {
        pTextEdit->append(text);
        }

        called this way:

        text = "Foo";
        ShowText(text, ui->text_edit2);

        could work.

        "In testa che avete, Signor di Ceprano?" -- Rigoletto

        In testa che avete, signor di Ceprano?

        L 1 Reply Last reply
        0
        • L Lost User

          What is a correct way to pass parameter / variable to function ? The attached snippet writes text to the GUI object and it is done in object constructor. My task is to pass ui->textEdit_2 to object function so it can be processed OUTSIDE constructor

          ui->setupUi(this);

          text = "Constructor ";
          ui->textEdit\_2->append(text);
          
          text = " Initialize DEBUG trace ";
          ui->textEdit\_2->append(text);
          

          private:
          public:
          Ui::MainWindow_C_CODE_FORM *ui;

          Here is my test function declaration: QString ShowText(QString text, QTextEdit *textEDIT ); I have tried several ways to access the function, but I am obviously "doing it wrong". PS I you cannot help "as is " , please, do not complain - it would work better if you ask what is missing instead. Thank you very much .

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Salvatore Terress wrote:

          I you cannot help "as is " , please, do not complain - it would work better

          Statements such as this are unnecessary, and make us suspect that you are a sock puppet for a certain member who was previously banned for abuse.

          1 Reply Last reply
          0
          • CPalliniC CPallini

            Something like

            void ShowText(QString text, QTextEdit * pTextEdit)
            {
            pTextEdit->append(text);
            }

            called this way:

            text = "Foo";
            ShowText(text, ui->text_edit2);

            could work.

            "In testa che avete, Signor di Ceprano?" -- Rigoletto

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Thanks, I have it working calling the function within constrictor. Appreciate your help getting this part fixed. I am trying to call it from another part of the code and getting this error

            /mnt/RAID_124/BT/BT_Oct20_BASE_/mdi/mainwindow.cpp:1274:
            error: member access into incomplete type 'Ui::MainWindow_C_CODE_FORM'
            mainwindow.cpp:1274:32: error: member access into incomplete type

            'Ui::MainWindow_C_CODE_FORM'

                ShowText(text,MWCCF->ui->textEdit());
                                       ^
            

            ../CCC_SOURCE/Bluetoothctl/../C_CODE_FORM/mainwindow_c_code_form.h:42:22: note: forward declaration of 'Ui::MainWindow_C_CODE_FORM'
            namespace Ui { class MainWindow_C_CODE_FORM; }
            ^

            I could use some help to solve this. PS This gives same error ShowText(text,MWCCF->ui->textEdit); Thanks

            L 1 Reply Last reply
            0
            • L Lost User

              Thanks, I have it working calling the function within constrictor. Appreciate your help getting this part fixed. I am trying to call it from another part of the code and getting this error

              /mnt/RAID_124/BT/BT_Oct20_BASE_/mdi/mainwindow.cpp:1274:
              error: member access into incomplete type 'Ui::MainWindow_C_CODE_FORM'
              mainwindow.cpp:1274:32: error: member access into incomplete type

              'Ui::MainWindow_C_CODE_FORM'

                  ShowText(text,MWCCF->ui->textEdit());
                                         ^
              

              ../CCC_SOURCE/Bluetoothctl/../C_CODE_FORM/mainwindow_c_code_form.h:42:22: note: forward declaration of 'Ui::MainWindow_C_CODE_FORM'
              namespace Ui { class MainWindow_C_CODE_FORM; }
              ^

              I could use some help to solve this. PS This gives same error ShowText(text,MWCCF->ui->textEdit); Thanks

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              SOLVED ?? This is silly , but it works

                  text = " START  DEBUG trace " ;
                  
                 finds first QTextEdit 
              
                  QTextEdit \*textEditPtr = MWCCF->centralWidget()->findChild();
              
                  or pass desired widget name (?) 
              
                  QTextEdit \*textEditPtr = MWCCF->centralWidget()->findChild("textEdit");
              

              if (textEditPtr)
              {
              qDebug("Found textEdit ");
              textEditPtr->append(text);
              }
              else
              qDebug() << "Did not find any QTextEdit";

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups