Results 1 to 6 of 6

Thread: Call to QDialog opens 2 windows

  1. #1
    Join Date
    Aug 2010
    Posts
    28
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Call to QDialog opens 2 windows

    I am new to qt so please forgive my ignorance. I have created a dialog box using qt creator. When I call this from my main window which I have a button for, the call opens up my qdialog box but also a new dialog box. Not sure what is going on. Here is the revelant parts of my code

    itemmaintenance.cpp

    void ItemMaintenance:n_pricingButton_clicked()
    {
    // itemPrice i;
    itemPrice *ip = new itemPrice();
    ip->show();
    }

    itemPrice.h
    #ifndef ITEMPRICE_H
    #define ITEMPRICE_H

    #include <QDialog>
    #include "ui_itemPrice.h"
    #include <QTableView>
    #include <QtSql>

    namespace Ui {
    class itemPrice;
    }

    class itemPrice : public QDialog
    , public Ui::itemPrice
    {
    Q_OBJECT

    public:
    itemPrice(QWidget *parent = 0);
    virtual ~itemPrice();

    private:
    Ui::itemPrice *ui;
    QSqlTableModel *ipmodel;
    QTableView *iptableView;

    private slots:
    void loadData(QString);
    };

    #endif // ITEMPRICE_H

    itemprice.cpp
    #include "itemprice.h"

    itemPrice::itemPrice(QWidget *parent) :
    QDialog(parent)
    ,ui(new Ui::itemPrice)
    {
    ui->setupUi(this);
    // setupUi(this);
    loadData(" ");
    }

    itemPrice::~itemPrice()
    {
    delete ui;
    }

    void itemPrice::loadData(QString partNumber)
    {

    ipmodel = new QSqlTableModel;
    ipmodel->setTable("in_price");
    ipmodel->setEditStrategy(QSqlTableModel::OnManualSubmit) ;
    ipmodel->setSort(2,Qt::AscendingOrder);
    if(partNumber > " ") ipmodel->setFilter(QString("partNumber = '%1'").arg(partNumber));
    ipmodel->select();

    iptableView = new QTableView;
    iptableView->close();
    iptableView->setModel(ipmodel);
    iptableView->setColumnHidden(0,true);
    iptableView->setColumnHidden(1,true);
    iptableView->show();
    }

    Please help.

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Call to QDialog opens 2 windows

    It looks like this is the issue:
    Qt Code:
    1. iptableView = new QTableView;
    2. // don't you want something like:
    3. // iptableView = new QTableView(this); //and don't show() it separate?
    4.  
    5. //*** don't forget to use layouts ***
    6. iptableView->close();
    7. iptableView->setModel(ipmodel);
    8. iptableView->setColumnHidden(0,true);
    9. iptableView->setColumnHidden(1,true);
    10. iptableView->show(); //here you show some widget that, i think, you want to be a child of your dialog
    To copy to clipboard, switch view to plain text mode 

    Anyway, i don't really understood your design, if you created the dialog in the Designer, why are you adding widgets with code? You could have added that QTableView from the designer.

    ***i'm not sure that you can add widgets to the designer created dialog with using layouts (i never done that before), if you can't do it, you can add the QTableView in the designer

    Also ipmodel = new QSqlTableModel; should have a parent, or else you should manually delete the pointer.

  3. #3
    Join Date
    Aug 2010
    Posts
    28
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Call to QDialog opens 2 windows

    I changed the code for the qtableview to add this and it got me closer. If I understand what you are saying, the fact that I added a table view in the creator and called it iptableView, why am I adding it again with the the new? What happens now is that the window opens up with 2 tableviews in it. When I remove the iptableview = new QTableView(this) and click the button to call the form, the application errors out.

  4. #4
    Join Date
    Aug 2010
    Posts
    28
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Call to QDialog opens 2 windows

    You are right with regard the last statement

    10.iptableView->show(); //here you show some widget that, i think, you want to be a child of your dialog

    This is the object name of the table view on my dialog window (iptableView). But it appears to create a new tableview and ignore the one on my dialog window.

  5. #5
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Call to QDialog opens 2 windows

    Quote Originally Posted by rdjenner View Post
    Qt Code:
    1. //iptableView->show(); //comment this line
    To copy to clipboard, switch view to plain text mode 
    Comment that line (and see what happens), maybe you don't have two widgets there (but it look like you have, because you have QTableView *iptableView; in your class declaration and you initialise that not the one that you said you put in your designer .ui file) also next time use [ code ] and [ /code ] around code (without spaces)

    LE:
    Use:
    Qt Code:
    1. //iptableView = new QTableView; // comment this
    2. //ui->iptableView_Name_from_designer->close(); // comment this
    3.  
    4. //the following will use the QTableView you added to the designer
    5. ui->iptableView_Name_from_designer->setModel(ipmodel);
    6. ui->iptableView_Name_from_designer->setColumnHidden(0,true);
    7. ui->iptableView_Name_from_designer->setColumnHidden(1,true);
    8. //iptableView->show(); // commented
    To copy to clipboard, switch view to plain text mode 
    also comment from the header file the line: //QTableView *iptableView;

    And don't forget the parent for your model, or manually delete, or you will have a leak
    Last edited by Zlatomir; 14th August 2010 at 00:44.

  6. #6
    Join Date
    Aug 2010
    Posts
    28
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Call to QDialog opens 2 windows

    That did it. Thank you SOOOOOOOOOOOOOOOOOOOOO much.

Similar Threads

  1. Replies: 4
    Last Post: 13th September 2009, 15:40
  2. Dialog opens twice
    By ulmly in forum Qt Programming
    Replies: 9
    Last Post: 30th June 2009, 19:25
  3. Shell opens when start Qt app
    By giusepped in forum Qt Programming
    Replies: 15
    Last Post: 2nd February 2009, 06:20
  4. QDialog::exec : Recursive call detected.
    By node_ex in forum Qt Programming
    Replies: 4
    Last Post: 29th June 2008, 17:50
  5. Replies: 1
    Last Post: 28th July 2006, 14:10

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.