Results 1 to 2 of 2

Thread: Use currenttext comboBox for query

  1. #1
    Join Date
    Apr 2017
    Posts
    1
    Platforms
    Windows

    Default Use currenttext comboBox for query

    Hello,

    In my database I have a table called:

    Qt Code:
    1. create table Cursos(
    2. ID_curso int not null auto_increment,
    3. Nome_curso varchar (50),
    4. primary key (ID_curso)
    5. )default charset = utf8;
    6.  
    7. And one table called Cadastrados:
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. create table Cadastrados(
    2. Nome varchar(50),
    3. Matricula varchar(9) unique,
    4. Curso_id int not null,
    5. primary key (Matricula),
    6. foreign key (Curso_id) references Cursos (ID_Curso)
    7. )default charset = utf8;
    To copy to clipboard, switch view to plain text mode 

    Using QT, I was able to list all Cursos.Nome_curso with comboBox:

    Qt Code:
    1. ui->setupUi(this);
    2. model->setQuery("select nome_curso from Cursos");
    3. ui->comboBox->setModel(model);
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Use currenttext comboBox for query

    To display the data from the second table You need a Cursos.id_curso and not Cursos.Nome_curso. So the model query should be "select nome_curso, id_curso frim Cursos". Try think the rest yourself

Similar Threads

  1. Qt Query
    By anh5kor in forum Newbie
    Replies: 5
    Last Post: 29th December 2015, 15:58
  2. Replies: 7
    Last Post: 16th April 2015, 17:11
  3. Filling a ComboBox with SQL query result
    By igr in forum Qt Programming
    Replies: 1
    Last Post: 1st September 2014, 17:16
  4. Replies: 1
    Last Post: 27th August 2014, 04:16
  5. currentText in Qcombobox
    By Vidhya in forum Qt Programming
    Replies: 9
    Last Post: 25th July 2012, 07:57

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.