Results 1 to 8 of 8

Thread: taking input from the input box

  1. #1
    Join Date
    Jul 2011
    Location
    Kolkata,India
    Posts
    18
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default taking input from the input box

    i want to take input from a textbox/textarea.
    what are the classes needed for it?
    and if i want to check the validity of the input(like int/float etc.) are there any inbuilt functions?
    i am a newbie in Qt programming.

  2. #2
    Join Date
    Jun 2011
    Posts
    26
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Default Re: taking input from the input box

    Hello neutrino,

    If you mean with textarea a QLineEdit class you can use the the text() method. Take a look here

    With regards checking the input I would suggest to take a look to the methods of Qstring class reference, here; and QByteArray, here.

    -E

  3. #3
    Join Date
    Jul 2011
    Location
    Kolkata,India
    Posts
    18
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: taking input from the input box

    can you give an example code.
    this is my first project(better to say first code)in Qt.

  4. #4
    Join Date
    Jun 2007
    Location
    India
    Posts
    33
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: taking input from the input box

    Take a look at QInputDialog if you want to receive values directly from user. For validating, inputdialog itself has different functions using which you can differentiate between double, int etc.
    Design is easy. All you do is stare at the screen until drops of blood form on your forehead.
    -Marty Neumeier

  5. #5
    Join Date
    Jun 2011
    Posts
    26
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Default Re: taking input from the input box

    Let me know if you dont understand any line of the code. I used qdebug(), then you can see when pressing a Qpushbutton the string data is captured and can be seen with Qt Creator (in application output).

    -E

    Qt Code:
    1. #include <QtGui>
    2.  
    3. class ExampleForNeutrino: public QWidget
    4. {
    5. Q_OBJECT
    6. public:
    7.  
    8. ExampleForNeutrino(QWidget *p = 0): QWidget(p)
    9. {
    10. textUser = new QLineEdit(tr("Insert text"));
    11. captureText = new QPushButton(tr("CaptureText"));
    12. connect(captureText,SIGNAL(clicked()),this, SLOT(storeText()));
    13.  
    14. QVBoxLayout *layout = new QVBoxLayout();
    15. layout->addWidget(textUser);
    16. layout->addWidget(captureText);
    17. setLayout(layout);
    18.  
    19. }
    20.  
    21. public slots:
    22. void storeText()
    23. {
    24. QByteArray str = textUser->text().toAscii();
    25. qDebug() << "Text captured by neutrino: " << str;
    26. }
    27.  
    28. private:
    29. QLineEdit *textUser;
    30. QPushButton *captureText;
    31. };
    32.  
    33. int main(int argc, char *argv[])
    34. {
    35.  
    36. QApplication a(argc, argv);
    37.  
    38. ExampleForNeutrino e;
    39. e.show();
    40. return a.exec();
    41. }
    42. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

  6. The following user says thank you to Ethan for this useful post:

    neutrino (30th September 2011)

  7. #6
    Join Date
    Jul 2011
    Location
    Kolkata,India
    Posts
    18
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: taking input from the input box

    cannot find main.moc
    Quote Originally Posted by Ethan View Post
    Let me know if you dont understand any line of the code. I used qdebug(), then you can see when pressing a Qpushbutton the string data is captured and can be seen with Qt Creator (in application output).

    -E

    Qt Code:
    1. #include <QtGui>
    2.  
    3. class ExampleForNeutrino: public QWidget
    4. {
    5. Q_OBJECT
    6. public:
    7.  
    8. ExampleForNeutrino(QWidget *p = 0): QWidget(p)
    9. {
    10. textUser = new QLineEdit(tr("Insert text"));
    11. captureText = new QPushButton(tr("CaptureText"));
    12. connect(captureText,SIGNAL(clicked()),this, SLOT(storeText()));
    13.  
    14. QVBoxLayout *layout = new QVBoxLayout();
    15. layout->addWidget(textUser);
    16. layout->addWidget(captureText);
    17. setLayout(layout);
    18.  
    19. }
    20.  
    21. public slots:
    22. void storeText()
    23. {
    24. QByteArray str = textUser->text().toAscii();
    25. qDebug() << "Text captured by neutrino: " << str;
    26. }
    27.  
    28. private:
    29. QLineEdit *textUser;
    30. QPushButton *captureText;
    31. };
    32.  
    33. int main(int argc, char *argv[])
    34. {
    35.  
    36. QApplication a(argc, argv);
    37.  
    38. ExampleForNeutrino e;
    39. e.show();
    40. return a.exec();
    41. }
    42. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

  8. #7
    Join Date
    Jun 2011
    Posts
    26
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Default Re: taking input from the input box

    In my case that code works (i did it and compiled in my pc)
    Clean the .pro file and leave only the line "SOURCES += main.cpp", and rebuild. Let me know if it works.

    If not, take a look here

    -E
    Last edited by Ethan; 30th September 2011 at 18:09.

  9. #8
    Join Date
    Jul 2011
    Location
    Kolkata,India
    Posts
    18
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: taking input from the input box

    my file name was different.
    i changed it to main.cpp and it worked.
    thanks

Similar Threads

  1. input raw data
    By Marina K. in forum Qt Programming
    Replies: 2
    Last Post: 17th May 2011, 18:28
  2. Raw Input in QT4
    By been_1990 in forum Qt Programming
    Replies: 5
    Last Post: 13th September 2010, 19:54
  3. input audio
    By addu in forum Qt Programming
    Replies: 9
    Last Post: 10th September 2009, 12:12
  4. QIntValidator input
    By chaos_theory in forum Qt Programming
    Replies: 4
    Last Post: 19th August 2007, 11:28
  5. regarding input widget
    By jagadish in forum Qt Tools
    Replies: 1
    Last Post: 28th June 2007, 13:07

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.