Use currenttext comboBox for query
-
Hello,
In my databse I have a table called:
create table Cursos( ID_curso int not null auto_increment, Nome_curso varchar (50), primary key (ID_curso) )default charset = utf8;And one table called Cadastrados:
create table Cadastrados( Nome varchar(50), Matricula varchar(9) unique, Curso_id int not null, primary key (Matricula), foreign key (Curso_id) references Cursos (ID_Curso) )default charset = utf8;Using QT, I was able to list all Cursos.Nome_curso with comboBox:
ui->setupUi(this); QSqlQueryModel *model = new QSqlQueryModel; model->setQuery("select nome_curso from Cursos"); ui->comboBox->setModel(model);But now I want to select one Nome_Curso of the combobox, and list all the Cadastrados of that respective curso (TableView, maybe?).
But I have no idea where to start. Any help?
Best regards,
DalPai -
Hello,
In my databse I have a table called:
create table Cursos( ID_curso int not null auto_increment, Nome_curso varchar (50), primary key (ID_curso) )default charset = utf8;And one table called Cadastrados:
create table Cadastrados( Nome varchar(50), Matricula varchar(9) unique, Curso_id int not null, primary key (Matricula), foreign key (Curso_id) references Cursos (ID_Curso) )default charset = utf8;Using QT, I was able to list all Cursos.Nome_curso with comboBox:
ui->setupUi(this); QSqlQueryModel *model = new QSqlQueryModel; model->setQuery("select nome_curso from Cursos"); ui->comboBox->setModel(model);But now I want to select one Nome_Curso of the combobox, and list all the Cadastrados of that respective curso (TableView, maybe?).
But I have no idea where to start. Any help?
Best regards,
DalPaiA TableView with a QSqlQueryModel could be an attempt for displaying the values from
Cadastradostable.Just use the
currentIndexChangedorcurrentTextChangedoractivatedsignal to get notified when one entry of yourQComboBoxis selected and update the model of yourQTableView