this is the last thing i am trying to do.if you know any good examples please guide me
Thanks!
this is the last thing i am trying to do.if you know any good examples please guide me
Thanks!
Paste the code you have so far.
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.
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.
so this much
Qt Code:
#include <QApplication> #include <QWidget> #include <QLineEdit> int main(int argc, char* argv[]) { QWidget window; password.move(480,750); password.resize(370,30); window.setWindowState(Qt::WindowFullScreen); window.show(); return app.exec(); }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
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![]()
@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.
@wenn32
read this:
http://doc.trolltech.com/4.6/signalsandslots.html
yeah i already read that article but its hard for me to catch up as i am new to QT.
and i know that you guys might think its my home work and no its not.if it was home work i would done this in WIN32 normal GUI but i really want to learn cross platform GUI so guys i don't want anyone helping me with entire code just help me learn this only just a push then i can move easily![]()
Qt Code:
#include <QApplication> #include <QWidget> #include <QLineEdit> { Q_OBJECT private slots: void open() { /* code to write to a file */ // i know this part. } }; int main(int argc, char* argv[]) { QWidget window; password.move(480,750); password.resize(370,30); window.setWindowState(Qt::WindowFullScreen); window.show(); return app.exec(); }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!
it's easier than you imagine:
Qt Code:
{ Q_OBJECT private: QLineEdit* password; private slots: void write_to_file() { // write it to your file } public: MyScreen() { password->move(480,750); password->resize(370,30); setWindowState(Qt::WindowFullScreen); connect( password,SIGNAL(returnPressed()), this ,SLOT(write_to_file()) } }; int main(int argc, char* argv[]) { NewSlot window; window.show(); return app.exec(); }To copy to clipboard, switch view to plain text mode
instead of using move and resize, you really should use layouts: http://doc.trolltech.com/4.6/layout.html
EDIT: Really should refresh before replying![]()
Bookmarks