PDA

View Full Version : QTCreator GUI How to link button with textarea



chs
9th November 2009, 09:47
Hello! I'm new in QT Programming and i tried to make a simple textarea with a button and I want to push the button and put some text like "Hello world" in the text area.

I know it could be simple but I read some example and I don't know how to do this.

Thanks a lot

yogeshgokul
9th November 2009, 10:35
Hello! I'm new in QT Programming and i tried to make a simple textarea with a button and I want to push the button and put some text like "Hello world" in the text area. I know it could be simple but I read some example and I don't know how to do this.Thanks a lot
You need to connect button's signal to a slot. In slot you can set text in your text area.

chs
9th November 2009, 11:01
There is some way to do it graffically? If I click with the right mouse button in my form button appears the option "go to slot", the I select Click() signal and it create a line in the code with a function that will be run when the button is clicked. I guess, i have to write there the code to write some text in the textarea but I don't know how to

yogeshgokul
9th November 2009, 11:18
There is some way to do it graffically?
This is most gracefull way ;)



If I click with the right mouse button in my form button appears the option "go to slot", the I select Click() signal and it create a line in the code with a function that will be run when the button is clicked. I guess, i have to write there the code to write some text in the textarea

Absolutely right :)



but I don't know how to
What text area you are using. Try this function call,

yourTextArea->setText("Hello World !!");

chs
9th November 2009, 11:33
This is my code:

void MainWindow::on_pushButton_clicked()
{
textEdit->setText("Hello World !!");
}


textEdit is the name of the text box.

I have this error:

mainwindow.cpp: In member function `void MainWindow::on_pushButton_clicked()':
mainwindow.cpp:18: error: `textEdit' was not declared in this scope
mainwindow.cpp:18: warning: unused variable 'textEdit'

How can I declare my text box?

thanks

JohannesMunk
9th November 2009, 17:32
Hi there!

I guess you set the name of your QTextEdit to "textEdit" using the designer. Mind the case sensitivity!

If that's the case, then probably your UI-class is aggregated as pointer member:

Try:
ui->textEdit->setText("Hello World !!");

If you want to avoid that - I do - next time you create a Qt Designer Form Class select "Multiple Inheritance" in the "Embedding of the UI Class" Radiofield which you find when you click "More" (options) button on the second page of the QtCreator Wizard where you choose a class name ...

HIH

Johannes

chs
9th November 2009, 19:11
Thanks very much, it works but i had to change setText by setPlainText


void MainWindow::on_buttonSend_released()
{
ui->textEdit>setPlainText("hello world!!");
}



I didn't understand what you talk about the class. I go to New, then I choose Qt Designer Form Class, Main window, more ->Multiple Inheritance and it overwrite my mainwindow.ui and mainwindow.cpp files
Can you explain to me some example about what I get doing it please?

Thanks you a lot

JohannesMunk
9th November 2009, 20:29
Hi!

When using multiple inheritance you can use:


void MainWindow::on_buttonSend_released()
{
textEdit->setPlainText("hello world!!");
}
without the ui!

Thats why it didn't work for you in the first place!

Joh

laki
23rd May 2011, 07:30
Hi!

When using multiple inheritance you can use:


void MainWindow::on_buttonSend_released()
{
textEdit->setPlainText("hello world!!");
}
without the ui!

Thats why it didn't work for you in the first place!

Joh

Hi All,
Thanks a lot !! even i am new to Qt and tried to push the text as you discussed above.

Know can some one tel me how move from one line to another in a textbrowser using a push Button .

thanks in advance,
Laki