Results 1 to 12 of 12

Thread: How to print[display] some text on a dialog?

  1. #1
    Join Date
    Mar 2007
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Exclamation How to print[display] some text on a dialog?

    hello all

    Could anybody please give me a code snippet which has a text input field and a button. If we enter some text into the text field and press the button, it should pop a new window with the same text inside. Urgent. please.

    I am using Qt 4.2.2 on windows.

    thanks in advance.

  2. #2
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to print[display] some text on a dialog?

    Have you looked at the QMessageBox class? Maybe even one of the static functions (like QMessageBox::information()) is enough.
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to print[display] some text on a dialog?

    @untamed:
    you should know that these kind of requests are not seen favorably on forums such as this one.
    We gladly help, but you should show that you are trying to solve your problem your self.
    So, show us what it is you have tried, and where exaclty your problem leis.
    We will help you then to solve your specific problem.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  4. #4
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to print[display] some text on a dialog?

    In general, you are right. You don't ask someone else to write code for you.

    But I can understand that if you're in a real hurry, you don't have time to do much research yourself. (Though you shouldn't disguise every question as such. )

    This forum is not here for nothing. And he did post in the newbie section. You should just point him in the right direction (as I did). The Qt library is quite big. I've been known to ask for directions myself.
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

  5. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to print[display] some text on a dialog?

    but what exactly did you answer to in my post?
    Yes, this forum is not here for nothing, but also not for people to get thier "home work" done for them.
    Even if someone is in a hurry, he/she should at least TRY SOMETHING.
    Being in a hurry is no reason not to do ANYTHING.

    Since the question is SO general, I could not see where to forward him to.
    You suggested QMessageBox.
    That is a valid oppinion, but I see no reason to bring QMessageBox up at all.
    If anything then:
    QDialog,QPushBUtton,QTextEdit and general reading about signals/slots.
    There - is that better?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  6. #6
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to print[display] some text on a dialog?

    Sure. You should know how these things work. But if you quickly want to display a message in a popup window, that's what QMessageBox is for. Why reinvent the wheel?
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

  7. #7
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to print[display] some text on a dialog?

    Why reinvent the wheel?
    because he wanted something which you can't do with a QMessageBox (unless you subclass it) - QMessageBox has no input fields.
    Could anybody please give me a code snippet which has a text input field and a button. If we enter some text into the text field and press the button, it should pop a new window with the same text inside.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  8. #8
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to print[display] some text on a dialog?

    Yes, of course. I was just assuming (for some reason) that the popup-window was the thing he had trouble with. Not the textfield and the button. Mea culpa.
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

  9. #9
    Join Date
    Mar 2007
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: How to print[display] some text on a dialog?

    I am really sorry to have asked such a question.
    I was in a hurry then, and i was thinking like if I happen to get some code, I can read and understand from that. I dint mean anybody to do my homework.

    hmm, I am quite new into this thing and even C++ too.

    So, I have created the first dialog with a text input filed and two buttons, ok and cancel. I havent used designer. I want to pop another dialog[or an alert] with the text copied from the first dialog's text input field when OK button is pressed. I know that i can pass the text through a string literal. How do i create that second dialog, thats my issue now. Will QMessageBox do?

    QMessageBox doesnt take inputs?
    I got this info from the documentation:
    QMessageBox::information ( QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton )

    so, I think the third field, const QString & text can be used to pass the text. Am I correct?
    so I can avoid creating a second dialog. My application[the actual assignment given] requires the use of alertboxes more, and if QMessageBox can take variables[strings] as inputs, it will be easy. Could anybody please clarify on this?

    Thank you.

  10. #10
    Join Date
    Mar 2007
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to print[display] some text on a dialog?

    I think this chunk of code is the core:
    void textdialog:op()
    {
    QString text = textedit->toHtml();

    QMessageBox::StandardButton ok;
    ok = QMessageBox::information(this, tr("Popped!"), tr("<p>You had entered:</p>""<p>%1</p>") .arg(text));
    }

    QMessageBox can take inputs.
    when the OK button is pressed, it calls the pop() function.


    Thanks everyone, I did it. Thanx Michiel for the understanding you showed. Thanks a lot to Sunil.Thaha for his patience when i disturbed him with silly doubts and for guiding me through each n every step.

  11. #11
    Join Date
    Mar 2007
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to print[display] some text on a dialog?

    I think this chunk of code is the core:
    Qt Code:
    1. void textdialog::pop()
    2. {
    3. QString text = textedit->toHtml();
    4.  
    5. QMessageBox::StandardButton ok;
    6. ok = QMessageBox::information(this, tr("Popped!"), tr("<p>You had entered:</p>""<p>%1</p>") .arg(text));
    7. }
    To copy to clipboard, switch view to plain text mode 

    QMessageBox can take inputs.
    when the OK button is pressed, it calls the pop() function.


    Thanks everyone, I did it. Thanx Michiel for the understanding you showed. Thanks to high_flyer for challenging me .
    Thanks a lot to Sunil.Thaha for his patience when i disturbed him with silly doubts and for guiding me through each n every step.
    Last edited by untamed; 5th June 2007 at 08:57. Reason: missing [code] tags

  12. #12
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to print[display] some text on a dialog?

    QMessageBox can take inputs.
    No it can't.
    The FUNCTION (in this case a static function) takes "input" parameters.
    But not the DIALOG.
    Its not the same.
    The input came from the QTextEdit widget, which you passed to the message box as a parameter.

    Thanks everyone, I did it. Thanx Michiel for the understanding you showed. Thanks to high_flyer for challenging me .
    Thanks a lot to Sunil.Thaha for his patience when i disturbed him with silly doubts and for guiding me through each n every step.
    Looks like end titels of a movie... or an oscar winner speach
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. Problem pasting text into a QTextEdit
    By Spockmeat in forum Qt Programming
    Replies: 8
    Last Post: 14th March 2009, 14:36
  3. Editable text in QGraphicsView
    By wysota in forum Qt Programming
    Replies: 8
    Last Post: 24th February 2007, 15:30
  4. Dialog positioning in GNOME
    By simk in forum Qt Programming
    Replies: 2
    Last Post: 16th March 2006, 09:41
  5. dialog box
    By Bahar in forum Qt Programming
    Replies: 3
    Last Post: 31st January 2006, 14:52

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.