Results 1 to 4 of 4

Thread: Showing form - help

  1. #1
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Showing form - help

    I hate to ask for help on something this simple, but I'm trying to learn C++ and Qt at the same time - can't find an answer in any of my books or online, so...

    I have a dialog (stninfodialog) that works fine when called from a menu pick on the main window.
    Now I need to call that dialog from a function in a different class.
    Simple in Java, but... I can't see how to do it in Qt/C++.

    Here is the relevant code from the main window cpp:

    Qt Code:
    1. #include <QtGui>
    2. #include "mainwindow.h"
    3. #include "ui_mainwindow.h"
    4. #include "makestndb.h"
    5.  
    6. MainWindow::MainWindow(QWidget *parent)
    7. : QMainWindow(parent), ui(new Ui::MainWindow)
    8. {
    9. ui->setupUi(this);
    10. setupActions();
    11. mStatLabel = new QLabel;
    12. statusBar()->addPermanentWidget(mStatLabel);
    13. connect(ui->call, SIGNAL(textChanged()), this, SLOT(updateStats()));
    14. StnInfoD = new StnInfoDialog;
    15. bool chkStnInfo = makeStnDB();
    16. }
    17.  
    18. void MainWindow::setupActions()
    19. {
    20. connect(ui->actionStn_Info, SIGNAL(triggered(bool)),
    21. this, SLOT(stnInfo()));
    22. }
    23.  
    24. void MainWindow::stnInfo()
    25. {
    26. StnInfoD->show();
    27. }
    To copy to clipboard, switch view to plain text mode 

    So, now the other class/function (makestndb.h/makestndb.cpp):

    makestndb.h

    Qt Code:
    1. #ifndef MAKESTNDB_H
    2. #define MAKESTNDB_H
    3.  
    4. #include "stninfodialog.h"
    5.  
    6. class makeStnDB {
    7. private:
    8. StnInfoDialog *StnInfoD;
    9.  
    10. };
    11.  
    12. bool makeStnDB();
    13.  
    14. #endif // MAKESTNDB_H
    To copy to clipboard, switch view to plain text mode 

    makestndb.cpp

    Qt Code:
    1. #include "makeStnDB.h"
    2. #include <iostream>
    3. #include <QString>
    4. #include <QtSql>
    5. #include "stninfodialog.h"
    6.  
    7. bool makeStnDB() {
    8. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    9. db.setDatabaseName("StnInfo");
    10. db.open();
    11.  
    12. //Check to see if stninfo exists...
    13. QSqlQuery query = QSqlQuery::QSqlQuery("StnInfo");
    14. query.exec("SELECT call FROM stnInfo");
    15.  
    16. if (query.isNull(1)) {
    17. query.exec("CREATE table stnInfo (id int recNum primary key, call varchar(8), "
    18. "name varchar(80), address1 varchar(80), accress2 varchar(80), "
    19. "city varchar(80), state varchar(80), state varchar(40), postalCode varchar(20), "
    20. "country varchar(40), grid varchar(8), cqZone varchar(8), ituZone varchar(8), "
    21. "latitude varchar(8), longitude varchar(8), licenseClass varchar(12)");
    22.  
    23. //HOW DO I CALL THE STNINFODIALOG FROM HERE?
    24.  
    25. }
    26. if (!db.open()) {
    27. return false;
    28. }
    29. return true;
    30. }
    To copy to clipboard, switch view to plain text mode 

    Thanks for any advice!
    Last edited by wysota; 27th October 2009 at 09:38. Reason: reformatted to look better

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

    Default Re: Showing form - help

    Does it even compile?

    Anyway, in C++ you can do it the same as in Java. The concept will be the same although the implementation of the concept will differ a bit.
    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. #3
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: Showing form - help

    Now I need to call that dialog from a function in a different class.
    Few ways... I use to create classes which inherits from QDialog and I include its header file wherever I want to create a dialog. Actually, in my opinion this is the cleaner way.

    But you can implement a public function which will give a pointer to the already created (or NULL if not) QDialog.

  4. The following user says thank you to jano_alex_es for this useful post:

    waynew (28th October 2009)

  5. #4
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Showing form - help

    Thanks guys, I got it working. Lots to learn.

Similar Threads

  1. Replies: 1
    Last Post: 19th March 2009, 09:41
  2. Help me to load one form over another form PushButton
    By wagmare in forum Qt Programming
    Replies: 7
    Last Post: 26th November 2008, 16:11
  3. visible main form?
    By triperzonak in forum Newbie
    Replies: 1
    Last Post: 12th June 2008, 09:00
  4. about qt/embedded widgets showing in ARM platform
    By xianshuiren in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 3rd December 2007, 05:48

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.