Results 1 to 4 of 4

Thread: Showing form - help

Threaded View

Previous Post Previous Post   Next Post Next Post
  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

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
  •  
Qt is a trademark of The Qt Company.