Passing variables between forms.
Ok i have been reading 100s of articles and posts on this and still cannot seem to get this to work!!
I have a login form where a database is queried. The username and the password are stored in variables. How do i use these variable on another form.
Thanks for your time and trouble :)
Re: Passing variables between forms.
that's simple
once you established the connection you can obtain these information wherever you want
creating QSqlDatabase object and using appropriate getters of it, take a look on QSqlDatabase documentation and you will know which one to use :)
tip, create an QSqlDatabase object like this
only thinq you have to keep somewhere is connectionName, personally I also have static structure to hold some vital information where connectionName is one of them
Re: Passing variables between forms.
What if i just want to store the username in a string variable and pass this between the forms? I have tried various things but cannot seem to get it to work. Thanks
Re: Passing variables between forms.
than you can either define setter in such form or introduce it into constructor
than from within main class (singleton) of your application You could set what you want in the form.
or
If by passing between forms you mean passing it between already existing variable than personally I would introduce something like asking signal and answer signal
Re: Passing variables between forms.
Could you give me an example of how to do this?
say i have a login form and a mainwindow, how would i use the username from the login form on the main window?
Thanks very much :)
Re: Passing variables between forms.
There isn't a single way of solving this (like most problems)
Have a public method on your main window which accepts a username and password?
Or perhaps the login form could be given a structure which it fills in and returns.
Or you could use a singleton which contains such information and everyone accesses.
Re: Passing variables between forms.
Hi squidge... could you show me an example of how to do this? If not, could your direct me to an article of how to do this.
I don't care if the code is messy, etc... i just want to get this to work. I'll tidy it up later :)
Thanks so much
Re: Passing variables between forms.
What bit are you struggling with?
I assume you already know how to create a public method, thats basic C++.
The contents of that method - assigning parameters to class member variables, is also basic C++.
So the only part left is the actual call, and so you simply instantiate a copy of the login form from within your main window (either allocate it on the stack and call a function which doesn't return until the login dialog is closed, or use the 'new' operator to allocate from the heap)
Re: Passing variables between forms.
Quote:
Originally Posted by
Splatify
Hi squidge... could you show me an example of how to do this? If not, could your direct me to an article of how to do this.
I don't care if the code is messy, etc... i just want to get this to work. I'll tidy it up later :)
Thanks so much
This is not a Qt problem, its a C++ problem. How do you pass data around classes?
Re: Passing variables between forms.
Ok I have successfully managed to do this now. Thanks so much for all your help. It really is appreciated :)
Edit:
Here is a link:
http://www.codeproject.com/KB/cs/pas...een_forms.aspx
I found which helped explain things in a fair amount of detail. I decided to use the first approach as it was the easiest and involved changing less of my code. In future I think i will plan a bit more before starting a project :)
Thanks once again.