PDA

View Full Version : Form QLineEdit



waynew
2nd November 2009, 23:56
Simple situation, but I can't find an answer.
Can anyone please point me to an example of how to setText() of a lineEdit field in a form from a different class? How to reference the form?
I tried this in the other class cpp:



Ui_Form *form;
form -> lineEditField -> setText("ABC");


Crashes the application :(

wysota
3rd November 2009, 09:06
How would you do it if you weren't using Qt but only C++?

squidge
3rd November 2009, 13:33
How about creating a public method in your ui class that can then access the ui elements on the other classes behalf? By default the ui is private, so only one class can access it. You shouldn't be accessing the ui from multiple classes anyway.

Remember Model View Architecture, the ui class updates the ui and nothing else. Another class handles the data model, and others handle the data.

waynew
3rd November 2009, 23:02
Thanks fatjuicymole - now it makes sense. :)

ambang_10111
5th November 2009, 21:16
Hi, i have created a project(Gui project) and in the main.cpp file i have some sql queries that gets data from a remote sever liekt this;
if(!query.exec("SELECT..........")){
qDebug()<<"FAIL";
}
while(query.next()){
QString name = query.value(0).toString();
qDebug() << name;
}
it works well and i have the results printed out like "abdnsh"
Now in my .ui i have Text Edit. How can i append the sql reults to the Text Edit in my .ui?
I'm a beginner, please i will appreciate