Results 1 to 18 of 18

Thread: Dynamic FOrms

  1. #1
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Dynamic FOrms

    hi,
    im new to QT programming,
    i want to create DYANMIC form based on DATABASE
    for ex:
    sqlite table contains how many forms to create and size of the form
    QT should connect sqlite table and it should create the forms

    pls guide me

    Bala

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Dynamic FOrms

    So what's the question?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    BalaQT (15th August 2009)

  4. #3
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Dynamic FOrms

    wysota> Thnks for replying me
    my question is :
    i) how to create forms from QT by reading from SQLITE table

    following is the code im using to show one window.
    Qt Code:
    1. #include <QApplication>
    2. #include <QGridLayout>
    3. #include <QPushButton>
    4. #include <QTextBox>
    5. #include <QProcess>
    6. #include "Connection.h"
    7. #include <QtCore/QVariant>
    8.  
    9. int main(int argc, char *argv[])
    10. {
    11. QApplication app(argc, argv);
    12. QWidget *win1 = new QWidget;
    13. QGridLayout *layout = new QGridLayout;
    14. QPushButton *ClickButton=new QPushButton("Click");
    15. QPushButton *CancelButton=new QPushButton("Cancel");
    16. QObject::connect(ClickButton,SIGNAL(clicked()),&app,SLOT(quit()));
    17. if(!createConnection())
    18. return 1;
    19. q.exec("SELECT * FROM ConfigTable");
    20. q.next();
    21. win1->setWindowTitle("Window1");
    22. win1->setFixedHeight(q.value(2).toInt());
    23. win1->setFixedWidth(q.value(3).toInt());
    24. layout->addWidget(ClickButton,0,0);
    25. layout->addWidget(CancelButton,0,2);
    26. win1->setLayout(layout);
    27. win1->show();
    28. return app.exec();
    29. }
    To copy to clipboard, switch view to plain text mode 

    How to create more than one windows, if the ConfigTable contain 2 or more records?

    Thnks
    Bala

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Dynamic FOrms

    I don't see a problem... just use a for() loop and in each iteration create a widget, fill it with child widgets and show it. Alternatively you can use QUiLoader if you can afford storing ui files in the database.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    BalaQT (15th August 2009)

  7. #5
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Dynamic FOrms

    Sir, thnks for the reply,
    i got the logic. but dont know how to do it in QT coding. pls provide me source code with for loop to create child widgets

    Thnks
    Bala

  8. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Dynamic FOrms

    How can I provide code if I don't know what the database holds?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. The following user says thank you to wysota for this useful post:

    BalaQT (15th August 2009)

  10. #7
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Dynamic FOrms

    Table Details
    Database : SQLITE
    Table Name : ConfigTable
    Fields :
    FormId Numeric
    FormName Text
    FormHeight Numeric
    FormWidth Numeric

    ConfigTable location : E:\Bala\Ramana\DynamicForm\DynaBase

    connection.h
    Qt Code:
    1. #ifndef CONNECTION_H
    2. #define CONNECTION_H
    3.  
    4. #include <QMessageBox>
    5. #include <QSqlDatabase>
    6. #include <QSqlError>
    7. #include <QSqlQuery>
    8.  
    9. static bool createConnection()
    10. {
    11. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    12. //db.setDatabaseName(":memory:");
    13. //db.setDatabaseName("e:/BALA/hirola");
    14. db.setDatabaseName("e:/BALA/Ramana/DynamicForm/DynaBase");
    15. if (!db.open()) {
    16. QMessageBox::critical(0, qApp->tr("Cannot open database"),
    17. qApp->tr("Unable to establish a database connection.\n"
    18. "This example needs SQLite support. Please read "
    19. "the Qt SQL driver documentation for information how "
    20. "to build it.\n\n"
    21. "Click Cancel to exit."), QMessageBox::Cancel);
    22. return false;
    23. }
    24.  
    25.  
    26. return true;
    27. }
    28. #endif
    To copy to clipboard, switch view to plain text mode 

    DynamicTable.Cpp
    Qt Code:
    1. #include <QApplication>
    2. #include <QGridLayout>
    3. #include <QPushButton>
    4. #include <QProcess>
    5. #include "Connection.h"
    6. #include <QtCore/QVariant>
    7.  
    8.  
    9. int main(int argc, char *argv[])
    10. {
    11. QApplication app(argc, argv);
    12. QWidget *win1 = new QWidget;
    13. QGridLayout *layout = new QGridLayout;
    14. QPushButton *ClickButton=new QPushButton("Click");
    15. QPushButton *CancelButton=new QPushButton("Cancel");
    16. QObject::connect(ClickButton,SIGNAL(clicked()),&app,SLOT(quit()));
    17. if(!createConnection())
    18. return 1;
    19. q.exec("SELECT * FROM ConfigTable");
    20. QString salary;
    21. q.next();
    22. win1->setWindowTitle("Window1");
    23. win1->setFixedHeight(q.value(2).toInt()); //FormHeight
    24. win1->setFixedWidth(q.value(3).toInt()); //FormWidth
    25. layout->addWidget(ClickButton,0,0);
    26. layout->addWidget(CancelButton,0,2);
    27. win1->setLayout(layout);
    28. win1->show();
    29. return app.exec();
    30. }
    To copy to clipboard, switch view to plain text mode 

    This is working fine for ONE ROW, ONE WINDOW.
    how to create n windows, if n rows are in configtable.

    Thnks
    Bala

  11. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Dynamic FOrms

    Qt Code:
    1. while(q.next()){
    2. QWidget *w = new QWidget;
    3. w->setWindowTitle(...);
    4. w->setWFixedHeight(q.value(2).toInt());
    5. ...
    6. w->show();
    7. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. The following user says thank you to wysota for this useful post:

    BalaQT (14th August 2009)

  13. #9
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Dynamic FOrms

    Thnks wysota
    it solved my problem.
    im new to QT. I understand SIMPLE OR BASIC means not easy untill u familiar with it.
    i love QT.but im a beginner. so pls consider me,even if i ask any dumb questions.

    i)what is the command for position the forms (LEFT AND TOP)?

    Thnks
    Bala

  14. #10
    Join Date
    Jul 2009
    Posts
    139
    Thanks
    13
    Thanked 59 Times in 52 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Dynamic FOrms

    Qt Code:
    1. w->move(x, y);
    To copy to clipboard, switch view to plain text mode 

  15. The following user says thank you to numbat for this useful post:

    BalaQT (21st August 2009)

  16. #11
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Dynamic FOrms

    thanks wysota

    its working fine, but i have more doubts in this

    how can i access the created window's widgets?
    for ex:
    a form displayed with 2 line edits in it.
    createLineedit is the function im using to create a lineedit.

    createLineedit() will be called 2 times to create 2 lineedits;

    hw can i access the values in it, when i press one pushbutton

    the follwing code called frm main.cpp
    createLineedit("id")
    createLineedit("name");

    How to take the values TYPED in id,name line edit ,when the user press Savepushbutton?

    pls guide me

  17. #12
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Dynamic FOrms

    any experts pls reply me.

    My need is i want to create dynamic widgets and dynamic forms..
    Im successful in creating dynamic forms and dynamic widgets, but How can i access the widget's value's?

    since all widgets have same name, i can able to take the latest value only
    how can i access all the values?

    pls guide me

    Thanks
    Bala

  18. #13
    Join Date
    Jul 2009
    Posts
    139
    Thanks
    13
    Thanked 59 Times in 52 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Dynamic FOrms

    If you have saved the widgets in a list you can just access that list:
    Qt Code:
    1. for (int i = 0; i < list.size(); i++)
    2. qDebug() << list[i].text();
    To copy to clipboard, switch view to plain text mode 
    If you haven't saved a list, you can get one from your top-level widget. This will get all line edits which you can then iterate as above.
    Qt Code:
    1. QList<QLineEdit *> myEdits = parentWidget.findChildren<QLineEdit *>();
    To copy to clipboard, switch view to plain text mode 

  19. The following user says thank you to numbat for this useful post:

    BalaQT (22nd August 2009)

  20. #14
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Dynamic FOrms

    Thnks nimbut,
    Its working.
    one more doubt in connecting SIGNALS AND SLOT

    For better understanding, i will explain my need.
    im creating forms and lineedit,pushbutton,label DYNAMICALLY frm a DB.


    void DynamicControls::createPushButton(QString Wstr,QString WTip,int x,int y)
    {
    pushButton=new QPushButton(Wstr);
    pushButton->setToolTip(WTip);
    layout->addWidget(pushButton,x,y);
    }


    This function will be called in CreateDynamicForm shown below:
    Qt Code:
    1. void DynamicControls::CreateDynamicForm()
    2. {
    3. QSqlQuery q1,q2;
    4. q1.exec("select * from FormMaster where FormVisible=1 order by FormId");
    5. while(q1.next())
    6. {
    7. tableName=q1.value(7).toString();
    8. q2.exec("select * from WidgetMaster where FormId=" + q1.value(0).toString() + " and WVisible=1 order by RowNo,ColumnNo");
    9. while(q2.next())
    10. {
    11. if(q2.value(2).toString()=="lineedit")
    12. {
    13. createLineEdit(q2.value(3).toString(),q2.value(1).toString(),q2.value(6).toInt(),q2.value(7).toInt());
    14.  
    15. else if(q2.value(2).toString()=="PushButton")
    16. {
    17. createPushButton(q2.value(3).toString(),q2.value(1).toString(),q2.value(6).toInt(),q2.value(7).toInt());
    18. }
    19. }
    20. }
    To copy to clipboard, switch view to plain text mode 


    The CreateDynamicForm will be called in CONSTRUCTOR
    i want to know hw to connect signals
    ex:
    if the created buttons name is SAVE , then my own slot UPDATEtable() has to be called..
    how can i do it.

    since its dynamic , im getting some err in the following connect
    (frankly i dont know how to connect a dynamically created button into CONNECT())
    QObject::connect(pushbutton, SIGNAL(clicked()),this,SLOT(updateTable1(IndxValue 1)));

    since all the pushbuttons names are same, connect not working properly.

    how to create a connect for dynamically created pushbuttons...

    Bala

  21. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Dynamic FOrms

    Come on, all the time you are facing strictly C++ issues. We don't teach C++ nor basics of programming here - get a decent book on C++ to learn about pointers.

    As for your last problem - you are passing a value to the slot in the connect statement which is forbidden. See the FAQ section of this site.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  22. #16
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Dynamic FOrms

    hi,
    Thnks wysota, i will surely study on it. but pls help me here.

    a)I've managed to create dynamic buttons.
    Now I am having a problem with being able to tell which button was pressed. The button objects are created at runtime and they're added to QList. How do I find out which button in the array was clicked?

    ex: 5 buttons are created frm DB. (all are having same name pushbutton)
    1)new , 2) save 3)del 4)view 5)exit

    i want to perform particular actions according to button click.
    how can i know which button was clicked?

    Any suggestions?

    Thnks
    Bala

  23. #17
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Dynamic FOrms

    what is the need of sending pms if you posted your topic here and getting replies?

    there is a function sender() which you can call in a slot to check which object called that slot.

    QList<QPushButton *> btns;
    void createbuttons()
    {
    btns<<new QPushButton("abc",this)<<new QPushButton("abc",this)<<new QPushButton("abc",this);
    connect all these buttons to a slot myslot();
    }

    void myslot()
    {
    QObject* o = sender();
    if(o==btns[0]) etc...
    }

  24. #18
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Dynamic FOrms

    Quote Originally Posted by BalaQT View Post
    how can i know which button was clicked?
    I'd suggest using QSignalMapper.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Linking Qt in a dynamic library
    By dave_mm0 in forum Qt Programming
    Replies: 4
    Last Post: 18th July 2009, 16:28
  2. Share a variable between forms
    By sepehr in forum Qt Programming
    Replies: 4
    Last Post: 29th January 2009, 07:05
  3. Custom shaped forms and controls
    By AlbertGoodwill in forum Qt Programming
    Replies: 1
    Last Post: 19th October 2007, 06:35
  4. Dynamic Language Switching
    By Salazaar in forum Newbie
    Replies: 7
    Last Post: 29th June 2007, 12:00
  5. Switching static to dynamic ui loading
    By s_a_white in forum Newbie
    Replies: 4
    Last Post: 26th June 2006, 15:57

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.