Results 1 to 9 of 9

Thread: QTCreator GUI How to link button with textarea

  1. #1
    Join Date
    Nov 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTCreator GUI How to link button with textarea

    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

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTCreator GUI How to link button with textarea

    Quote Originally Posted by chs View Post
    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.

  3. #3
    Join Date
    Nov 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTCreator GUI How to link button with textarea

    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

  4. #4
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTCreator GUI How to link button with textarea

    Quote Originally Posted by chs View Post
    There is some way to do it graffically?
    This is most gracefull way

    Quote Originally Posted by chs View Post
    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

    Quote Originally Posted by chs View Post
    but I don't know how to
    What text area you are using. Try this function call,
    Qt Code:
    1. yourTextArea->setText("Hello World !!");
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Nov 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTCreator GUI How to link button with textarea

    This is my code:

    void MainWindow:n_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:n_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

  6. #6
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTCreator GUI How to link button with textarea

    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

  7. #7
    Join Date
    Nov 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTCreator GUI How to link button with textarea

    Thanks very much, it works but i had to change setText by setPlainText


    void MainWindow:n_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

  8. #8
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTCreator GUI How to link button with textarea

    Hi!

    When using multiple inheritance you can use:

    Qt Code:
    1. void MainWindow::on_buttonSend_released()
    2. {
    3. textEdit->setPlainText("hello world!!");
    4. }
    To copy to clipboard, switch view to plain text mode 
    without the ui!

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

    Joh

  9. #9
    Join Date
    May 2011
    Posts
    2
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X

    Question Re: QTCreator GUI How to link button with textarea

    Quote Originally Posted by JohannesMunk View Post
    Hi!

    When using multiple inheritance you can use:

    Qt Code:
    1. void MainWindow::on_buttonSend_released()
    2. {
    3. textEdit->setPlainText("hello world!!");
    4. }
    To copy to clipboard, switch view to plain text mode 
    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

Similar Threads

  1. link keybooard 'enter' button to our callback.
    By newtowindows in forum Qt Programming
    Replies: 3
    Last Post: 18th April 2011, 19:22

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.