How to pass parameter (pointer) to function ?
-
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 .
-
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 .
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
-
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 .
-
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 .
-
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
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
-
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
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";