tags:

views:

185

answers:

1

Strange bug with a Qt dialog ( Qt4.6/windows)

If the dialog is started from MainWindow (from a toolbar/or menu action) and it is modal none of the text boxes will accept any edits. Other controls (drop down, buttons etc) all work.

If I make the dialog non-modal, with show() rather than exec(), it works perfectly!

Anyone come across anything like this?

example code:

#include "ui_testDlg.h"    
class TestDlg : public QDialog, public Ui::TestDlg
{
    Q_OBJECT;    
public:
    TestDlg(QWidget *parent=0)  {
        setupUi(this);
    }

    ~TestDlg(void) {}    

private:
    Ui::TestDlg ui;     
};

TestDlg.ui is just the simplest dialog box + lineEdit control created in QDesigner.

void MainWindow::onTest()
{
TestDlg *test = new TestDlg(this);
test->show();  // works
//or    
test->exec();  // opens dlg but can't type in it!
}

EDIT: It is the same problem if I just use a QInputWidget - and it is only a problem in MainWindow. So must be some signal I am blocking/consuming?

A: 

You could change the relation between TestDlg and Ui::TestDlg from subclassing to private member.

#include "ui_testdlg.h"

class TestDlg: public QDialog {
    Q_OBJECT
public:
    TestDlg(QWidget *parent = 0) : QDialog(parent), ui(new Ui::TestDlg)
    {
        ui->setupUi(this);
    }
   ~TestDlg()
    {
        delete ui;
    }

private:
    Ui::TestDlg*ui;
};

QtCreator defaults new widget classes like this and with this setup I did not have any problems with the QLineEdit. (Qt 4.6 on WinXP)

Fabian Wickborn
It's the same problem if I use QInputWidget:: so it must be something I am setting in Mainwindow, some signal I am capturing
Martin Beckett