Results 1 to 19 of 19

Thread: help with connect() without using QT creator

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Windows

    Default help with connect() without using QT creator

    Hello i am really having a bad time with connect().And i really need help

    1) I want my program to take input via the QT text box and copy the value to a file

    2) I want to take value from a text file every 10 seconds and update the value of the QT label

    i have no idea how to do this.Please help me and these are for just learning!

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: help with connect() without using QT creator

    There's several examples in the Qt docs that can be combined to provide the functionality that you want. Maybe start with a little c++ docs if you aren't familiar with the language.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  3. #3
    Join Date
    Jun 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: help with connect() without using QT creator

    this is the last thing i am trying to do.if you know any good examples please guide me
    Thanks!

  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: help with connect() without using QT creator

    Paste the code you have so far.

  5. #5
    Join Date
    Jun 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: help with connect() without using QT creator

    Its just for learning purpose i need some one help me understand the connect() so i asked some simple programs which will help me understand.

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: help with connect() without using QT creator

    I cannot help thinking this is a, "Can you do my homework?" type of request.

    There are plenty of examples of the use of connect() in the docs that come with Qt. You could start with reading Signals and Slots and Address Book Tutorial. Then look at the signals emitted by objects of class QLineEdit and QTimer to see what is useful for your purposes.

    When you have written some code, and still cannot get any joy, then come back with the code and questions about specific elements.

  7. #7
    Join Date
    Jun 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: help with connect() without using QT creator

    so this much

    Qt Code:
    1. #include <QApplication>
    2. #include <QWidget>
    3. #include <QLineEdit>
    4.  
    5.  
    6. int main(int argc, char* argv[])
    7. {
    8. QApplication app(argc, argv);
    9. QWidget window;
    10. QLineEdit password("",&window);
    11.  
    12.  
    13. password.move(480,750);
    14. password.resize(370,30);
    15. password.setEchoMode(QLineEdit::Password);
    16. window.setWindowState(Qt::WindowFullScreen);
    17.  
    18.  
    19. QObject::connect(&password,SIGNAL(returnPressed()),&password,SLOT(write_to_file()));
    20. window.show();
    21. return app.exec();
    22. }
    To copy to clipboard, switch view to plain text mode 

    now how do i create my own slot so that what i type in the line edit and press return it can be written to a file

  8. #8
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: help with connect() without using QT creator

    To use signals and slots you will need objects.

    So to create (define your own) new slots you need to create a class (maybe derive from another class), use Q_OBJECT macro in the class definition, and define the slots as member function (with "public slots:" access specifier)

    In your case you will need a class derived form QWidget (or QMainWindow or QDialog depends on how you want that piece of widget to look like) that will have a QLineEdit as a member (maybe a QString, that depends if you want to use the string more than send it to file) and that slot that will take a QString as a parameter and write it to a file (here you will use the QFile to do the write and read in binary or text file)

    Try to make what i explained here and if you get into troubles than post the code that is not doing what you wanted to do and we will help you

  9. #9
    Join Date
    Jun 2010
    Posts
    86
    Thanks
    10
    Thanked 6 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: help with connect() without using QT creator

    Quote Originally Posted by Zlatomir View Post
    To use signals and slots you will need objects.

    So to create (define your own) new slots you need to create a class (maybe derive from another class), use Q_OBJECT macro in the class definition, and define the slots as member function (with "public slots:" access specifier)

    In your case you will need a class derived form QWidget (or QMainWindow or QDialog depends on how you want that piece of widget to look like) that will have a QLineEdit as a member (maybe a QString, that depends if you want to use the string more than send it to file) and that slot that will take a QString as a parameter and write it to a file (here you will use the QFile to do the write and read in binary or text file)

    Try to make what i explained here and if you get into troubles than post the code that is not doing what you wanted to do and we will help you

    You told him to define a slot takes QString argument and didn't tell him how to pass this argument. He will need to use a QString argument signal not the returnPressed().

  10. #10
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: help with connect() without using QT creator

    @ahmdsd_ostora: good point
    Also, there are a lot more "improvements" to that little "design" of a class, maybe he will need more stuff (like username too, etc...) so my advice was only to give him the direction where to start not the "final design" of his class.

  11. #11
    Join Date
    Jun 2010
    Posts
    86
    Thanks
    10
    Thanked 6 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: help with connect() without using QT creator


  12. #12
    Join Date
    Jun 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: help with connect() without using QT creator

    Qt Code:
    1. #include <QApplication>
    2. #include <QWidget>
    3. #include <QLineEdit>
    4.  
    5. class NewSlot : public QWidget
    6. {
    7. Q_OBJECT
    8.  
    9. private slots:
    10. void open()
    11. {
    12. /* code to write to a file */
    13. // i know this part.
    14. }
    15. };
    16.  
    17.  
    18.  
    19. int main(int argc, char* argv[])
    20. {
    21. QApplication app(argc, argv);
    22. QWidget window;
    23. QLineEdit password("",&window);
    24.  
    25.  
    26. password.move(480,750);
    27. password.resize(370,30);
    28. password.setEchoMode(QLineEdit::Password);
    29. window.setWindowState(Qt::WindowFullScreen);
    30.  
    31.  
    32. QObject::connect(&password,SIGNAL(returnPressed()),&password,SLOT(write_to_file()));
    33. window.show();
    34. return app.exec();
    35. }
    To copy to clipboard, switch view to plain text mode 

    ok can i normally create a object of the class NewSlot and call in connect() and by the way how do i get the data of the password(QLineedit) field


    Thank you very much for helping me!

  13. #13
    Join Date
    Jun 2010
    Posts
    86
    Thanks
    10
    Thanked 6 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: help with connect() without using QT creator

    Quote Originally Posted by wenn32 View Post
    Qt Code:
    1. #include <QApplication>
    2. #include <QWidget>
    3. #include <QLineEdit>
    4.  
    5. class NewSlot : public QWidget
    6. {
    7. Q_OBJECT
    8.  
    9. private slots:
    10. void open()
    11. {
    12. /* code to write to a file */
    13. // i know this part.
    14. }
    15. };
    16.  
    17.  
    18.  
    19. int main(int argc, char* argv[])
    20. {
    21. QApplication app(argc, argv);
    22. QWidget window;
    23. QLineEdit password("",&window);
    24.  
    25.  
    26. password.move(480,750);
    27. password.resize(370,30);
    28. password.setEchoMode(QLineEdit::Password);
    29. window.setWindowState(Qt::WindowFullScreen);
    30.  
    31.  
    32. QObject::connect(&password,SIGNAL(returnPressed()),&password,SLOT(write_to_file()));
    33. window.show();
    34. return app.exec();
    35. }
    To copy to clipboard, switch view to plain text mode 

    ok can i normally create a object of the class NewSlot and call in connect() and by the way how do i get the data of the password(QLineedit) field


    Thank you very much for helping me!

    Why not making your class the one which holds the password LineEdit, instead of the QWidget object ??
    this will give your slot easy access to get the text

  14. #14
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: help with connect() without using QT creator

    EDIT: Really should refresh before replying

Similar Threads

  1. Replies: 16
    Last Post: 16th February 2010, 13:17
  2. How to connect?
    By starlon in forum Qt Programming
    Replies: 1
    Last Post: 18th October 2009, 23:24
  3. Replies: 4
    Last Post: 10th November 2006, 15:38
  4. connect
    By mickey in forum Newbie
    Replies: 15
    Last Post: 2nd August 2006, 22:42
  5. many connect
    By mickey in forum Qt Programming
    Replies: 3
    Last Post: 29th May 2006, 12:55

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
  •  
Qt is a trademark of The Qt Company.