graciano
14th January 2009, 12:17
Hi!
I wrote a dialog to input valid car plates (Portuguese format: http://pt.wikipedia.org/wiki/Matr%C3%ADculas_autom%C3%B3veis_em_Portugal )using Qt Designer. It works just fine.
Then i tried to write it again, but now not using Qt Designer.
This second version works but i get the following message :
Starting /home/torrao/Desktop/v7/automovel_sem_designer/automovel_sem_designer
QWidget::setTabOrder: 'first' and 'second' must be in the same window
QWidget::setTabOrder: 'first' and 'second' must be in the same window
/home/torrao/Desktop/v7/automovel_sem_designer/automovel_sem_designer exited with code 0
This must be an insignificant detail ... but i would apreciate some help :)
The code:
IdDoAutomovel.h
#ifndef IDDOAUTOMOVELDIALOG_H
#define IDDOAUTOMOVELDIALOG_H
#include <QDialog>
class QLabel;
class QLineEdit;
class QSpacerItem;
class QPushButton;
class QHBoxLayout;
class QVBoxLayout;
class QString;
class QRegExp;
class IdDoAutomovelDialog : public QDialog
{
Q_OBJECT
public:
IdDoAutomovelDialog(QWidget *parent = 0);
private slots:
void on_lineEdit_textChanged();
private:
QLabel *label;
QLineEdit *lineEdit;
QSpacerItem *horizontalSpacer;
QPushButton *okButton;
QPushButton *cancelButton;
QStringList *listaMatriculasValidas;
QVBoxLayout *verticalLayout;
QHBoxLayout *horizontalLayout;
QHBoxLayout *horizontalLayout_2;
};
#endif // IDDOAUTOMOVELDIALOG_H
IdDoAutomovel.cpp
#include <QtGui>
#include "IdDoAutomovelDialog.h"
IdDoAutomovelDialog::IdDoAutomovelDialog(QWidget *parent):QDialog(parent){
//Label
label = new QLabel("&MatrÃ*cula:");
//Line Edit
lineEdit = new QLineEdit;
//Buddyes
label->setBuddy(lineEdit);
//Spacer
horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
//OK Button
okButton = new QPushButton("Ok");
okButton->setEnabled(false);
//CANCEL Button
cancelButton = new QPushButton("Cancel");
cancelButton->setObjectName(QString::fromUtf8("cancelButton"));
//Validar a matrÃ*cula introduzida ( http://pt.wikipedia.org/wiki/Matr%C3%ADculas_autom%C3%B3veis_em_Portugal )
listaMatriculasValidas = new QStringList;
listaMatriculasValidas->append("[A-Za-z]{2,2}[-][0-9]{2,2}[-][0-9]{2,2}");
listaMatriculasValidas->append("[0-9]{2,2}[-][0-9]{2,2}[-][A-Za-z]{2,2}"); //or
listaMatriculasValidas->operator <<("[0-9]{2,2}[-][A-Za-z]{2,2}[-][0-9]{2,2}");
QRegExp regExp(listaMatriculasValidas->join("|"));
lineEdit->setValidator(new QRegExpValidator(regExp, this));
//Definir acções
connect(lineEdit, SIGNAL(textChanged(const QString &)),
this, SLOT(on_lineEdit_textChanged()));
connect(okButton, SIGNAL(clicked()),
this, SLOT(accept()));
connect(cancelButton, SIGNAL(clicked()),
this, SLOT(close()));
//layout Dialog
horizontalLayout = new QHBoxLayout;
horizontalLayout_2 = new QHBoxLayout;
verticalLayout = new QVBoxLayout;
horizontalLayout->addWidget(label);
horizontalLayout->addWidget(lineEdit);
horizontalLayout_2->addItem(horizontalSpacer);
horizontalLayout_2->addWidget(okButton);
horizontalLayout_2->addWidget(cancelButton);
verticalLayout->addLayout(horizontalLayout);
verticalLayout->addLayout(horizontalLayout_2);
//Tab order
QWidget::setTabOrder(lineEdit, okButton);
QWidget::setTabOrder(okButton, cancelButton);
setWindowTitle("MatrÃ*cula");
setLayout(verticalLayout);
}
void IdDoAutomovelDialog::on_lineEdit_textChanged(){
okButton->setEnabled(lineEdit->hasAcceptableInput());
}
Thanks
I wrote a dialog to input valid car plates (Portuguese format: http://pt.wikipedia.org/wiki/Matr%C3%ADculas_autom%C3%B3veis_em_Portugal )using Qt Designer. It works just fine.
Then i tried to write it again, but now not using Qt Designer.
This second version works but i get the following message :
Starting /home/torrao/Desktop/v7/automovel_sem_designer/automovel_sem_designer
QWidget::setTabOrder: 'first' and 'second' must be in the same window
QWidget::setTabOrder: 'first' and 'second' must be in the same window
/home/torrao/Desktop/v7/automovel_sem_designer/automovel_sem_designer exited with code 0
This must be an insignificant detail ... but i would apreciate some help :)
The code:
IdDoAutomovel.h
#ifndef IDDOAUTOMOVELDIALOG_H
#define IDDOAUTOMOVELDIALOG_H
#include <QDialog>
class QLabel;
class QLineEdit;
class QSpacerItem;
class QPushButton;
class QHBoxLayout;
class QVBoxLayout;
class QString;
class QRegExp;
class IdDoAutomovelDialog : public QDialog
{
Q_OBJECT
public:
IdDoAutomovelDialog(QWidget *parent = 0);
private slots:
void on_lineEdit_textChanged();
private:
QLabel *label;
QLineEdit *lineEdit;
QSpacerItem *horizontalSpacer;
QPushButton *okButton;
QPushButton *cancelButton;
QStringList *listaMatriculasValidas;
QVBoxLayout *verticalLayout;
QHBoxLayout *horizontalLayout;
QHBoxLayout *horizontalLayout_2;
};
#endif // IDDOAUTOMOVELDIALOG_H
IdDoAutomovel.cpp
#include <QtGui>
#include "IdDoAutomovelDialog.h"
IdDoAutomovelDialog::IdDoAutomovelDialog(QWidget *parent):QDialog(parent){
//Label
label = new QLabel("&MatrÃ*cula:");
//Line Edit
lineEdit = new QLineEdit;
//Buddyes
label->setBuddy(lineEdit);
//Spacer
horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
//OK Button
okButton = new QPushButton("Ok");
okButton->setEnabled(false);
//CANCEL Button
cancelButton = new QPushButton("Cancel");
cancelButton->setObjectName(QString::fromUtf8("cancelButton"));
//Validar a matrÃ*cula introduzida ( http://pt.wikipedia.org/wiki/Matr%C3%ADculas_autom%C3%B3veis_em_Portugal )
listaMatriculasValidas = new QStringList;
listaMatriculasValidas->append("[A-Za-z]{2,2}[-][0-9]{2,2}[-][0-9]{2,2}");
listaMatriculasValidas->append("[0-9]{2,2}[-][0-9]{2,2}[-][A-Za-z]{2,2}"); //or
listaMatriculasValidas->operator <<("[0-9]{2,2}[-][A-Za-z]{2,2}[-][0-9]{2,2}");
QRegExp regExp(listaMatriculasValidas->join("|"));
lineEdit->setValidator(new QRegExpValidator(regExp, this));
//Definir acções
connect(lineEdit, SIGNAL(textChanged(const QString &)),
this, SLOT(on_lineEdit_textChanged()));
connect(okButton, SIGNAL(clicked()),
this, SLOT(accept()));
connect(cancelButton, SIGNAL(clicked()),
this, SLOT(close()));
//layout Dialog
horizontalLayout = new QHBoxLayout;
horizontalLayout_2 = new QHBoxLayout;
verticalLayout = new QVBoxLayout;
horizontalLayout->addWidget(label);
horizontalLayout->addWidget(lineEdit);
horizontalLayout_2->addItem(horizontalSpacer);
horizontalLayout_2->addWidget(okButton);
horizontalLayout_2->addWidget(cancelButton);
verticalLayout->addLayout(horizontalLayout);
verticalLayout->addLayout(horizontalLayout_2);
//Tab order
QWidget::setTabOrder(lineEdit, okButton);
QWidget::setTabOrder(okButton, cancelButton);
setWindowTitle("MatrÃ*cula");
setLayout(verticalLayout);
}
void IdDoAutomovelDialog::on_lineEdit_textChanged(){
okButton->setEnabled(lineEdit->hasAcceptableInput());
}
Thanks