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. qtsqlquerymodel table veiw

qtsqlquerymodel table veiw

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 568 Views
  • 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.
  • GREYONG Offline
    GREYONG Offline
    GREYON
    wrote on last edited by
    #1

    Hello friends, I have connected may qt application to MySQL database. However I have two issues in which I need some help.

    • First what can be the best data type for the currency(money) in the data base and how can I include the symbol of the currency in the data base record such that even when am displaying my query results in querymodel table veiw,even the symbol for the currency is show instead of a number only?

    • When I use qtsqlququery model to view tables,each row (record) is numbered automatically,is the a way of displaying a table without having the rows numbered?

    • Lastly I have this query:

    void PUPILS_PAID_SCH_FEES_BY_GRADE::on_VIEW_PUPILS_clicked()
    {
        int sub=ui->comboBox->currentIndex();
    
        QSqlDatabase::database();
        querymodel=new QSqlQueryModel;
        QSqlQuery query;
    
        switch (sub)
        {
        case 0:
    
        querymodel->setQuery("SELECT SURNAME,LASTNAME,GRADE,CLASS,AMOUNT,DATE FROM payments WHERE GRADE=8");
    if(query.size()>0){
    
        ui->tableView->setModel(querymodel);
    }
    else
     {
    QMessageBox::warning(this,"warning", "no one has paid in this class");
    }
        
    
    

    What I want is that if no one has paid in grade 8 classes,nothing should be displayed only the warning message,however what is happening is that even when some one has paid in this class, the table is not shown only the warning message is coming.where iam I going wrong please.I will appreciate your help.

    JonBJ 1 Reply Last reply
    0
    • GREYONG GREYON

      Hello friends, I have connected may qt application to MySQL database. However I have two issues in which I need some help.

      • First what can be the best data type for the currency(money) in the data base and how can I include the symbol of the currency in the data base record such that even when am displaying my query results in querymodel table veiw,even the symbol for the currency is show instead of a number only?

      • When I use qtsqlququery model to view tables,each row (record) is numbered automatically,is the a way of displaying a table without having the rows numbered?

      • Lastly I have this query:

      void PUPILS_PAID_SCH_FEES_BY_GRADE::on_VIEW_PUPILS_clicked()
      {
          int sub=ui->comboBox->currentIndex();
      
          QSqlDatabase::database();
          querymodel=new QSqlQueryModel;
          QSqlQuery query;
      
          switch (sub)
          {
          case 0:
      
          querymodel->setQuery("SELECT SURNAME,LASTNAME,GRADE,CLASS,AMOUNT,DATE FROM payments WHERE GRADE=8");
      if(query.size()>0){
      
          ui->tableView->setModel(querymodel);
      }
      else
       {
      QMessageBox::warning(this,"warning", "no one has paid in this class");
      }
          
      
      

      What I want is that if no one has paid in grade 8 classes,nothing should be displayed only the warning message,however what is happening is that even when some one has paid in this class, the table is not shown only the warning message is coming.where iam I going wrong please.I will appreciate your help.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @GREYON
      MySQL does not have a currency type. Nor does C++. Which is a bit of an issue. I used DECIMAL(8, 2), you could increase the first argument if you want larger amounts. The really important thing is that you do not store any kind of currency symbol in the database, and you do not get tempted to store it as string like "123.45". When you want to display the amount only then do you add the symbol, e.g. in a QStyledItemDelegate for a QTableView.

      Don't know about the row numbering, depends what widget you are using to display which you do no not mention.

      Your query code is all over the place. There is no relationship between QSqlQuery query; variable and querymodel->setQuery(...), so query.size() is not going to tell you anything, is probably always 0, and so the else is followed. QSqlDatabase::database(); is a statement which does nothing. Check out the examples in Qt's documentation.

      GREYONG 1 Reply Last reply
      0
      • JonBJ JonB

        @GREYON
        MySQL does not have a currency type. Nor does C++. Which is a bit of an issue. I used DECIMAL(8, 2), you could increase the first argument if you want larger amounts. The really important thing is that you do not store any kind of currency symbol in the database, and you do not get tempted to store it as string like "123.45". When you want to display the amount only then do you add the symbol, e.g. in a QStyledItemDelegate for a QTableView.

        Don't know about the row numbering, depends what widget you are using to display which you do no not mention.

        Your query code is all over the place. There is no relationship between QSqlQuery query; variable and querymodel->setQuery(...), so query.size() is not going to tell you anything, is probably always 0, and so the else is followed. QSqlDatabase::database(); is a statement which does nothing. Check out the examples in Qt's documentation.

        GREYONG Offline
        GREYONG Offline
        GREYON
        wrote on last edited by
        #3

        @JonB
        Thanks for your help,the widget am using is a model based table view

        GREYONG 1 Reply Last reply
        0
        • GREYONG GREYON

          @JonB
          Thanks for your help,the widget am using is a model based table view

          GREYONG Offline
          GREYONG Offline
          GREYON
          wrote on last edited by
          #4

          @GREYON
          what do you by saying your code is all over the place?what is your suggestion? how can I use the if statement successfully?

          1 Reply Last reply
          0

          • Login

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