Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Use currenttext comboBox for query
Forum Updated to NodeBB v4.3 + New Features

Use currenttext comboBox for query

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 558 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DalPai
    wrote on last edited by
    #1

    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

    the_T 1 Reply Last reply
    0
    • D 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,
      DalPai

      the_T Offline
      the_T Offline
      the_
      wrote on last edited by
      #2

      @DalPai

      A TableView with a QSqlQueryModel could be an attempt for displaying the values from Cadastrados table.

      Just use the currentIndexChanged or currentTextChanged or activated signal to get notified when one entry of your QComboBox is selected and update the model of your QTableView

      -- No support in PM --

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved