2 Attachment(s)
display a line number of my tableView not working
Hi, i'm trying here to display on my label_9 the number of the selected line of my table so i used this code
Attachment 12999
and the problem is that label_9 is not taking any number
Attachment 13000
i used also
Code:
int k = ui->tableView->currentIndex().row();
ui->label_9->setNum(k)
and the lable is keep showing me -1 !
Re: display a line number of my tableView not working
When you run your code in the debugger and get to this line:
Quote:
int k = ui->tableView->currentIndex().row();
what does the debugger tell you the value of k" is?
Quote:
int k = ui->tableView->currentIndex().row();
ui->label_9->setNum(k)
Where does this code appear? In a slot, in a constructor, somewhere else? My magic code viewer isn't working today, so trying to determine what is wrong with your code won't be easy unless you post more of it.
Re: display a line number of my tableView not working
thnx for your Reply
well my goal is to have an update on label_9 and to show the current row of the selected line in the tableView
this is my current code for now
Code:
void personnel_click::arrow()
{
int k = ui->tableView->currentIndex().row();
ui->label_9->setNum(k);
ui->label_9->update();
}
and yes this code appear in a slot ; my k is taking always the value of -1 even when i select another line in the table
and here all the .cpp
Code:
#include "personnel_click.h"
#include "ui_personnel_click.h"
#include "ajouter_p.h"
#include "afficher_p.h"
#include "supprimer_p.h"
#include "personnel.h"
#include <QSqlDatabase>
#include <QMessageBox>
#include <QSqlQuery>
#include <QSqlQueryModel>
#include <bien.h>
personnel_click
::personnel_click(QWidget *parent
) : ui(new Ui::personnel_click)
{
ui->setupUi(this);
}
personnel_click::~personnel_click()
{
delete ui;
}
void personnel_click::on_pushButton_clicked()
{
ui->stackedWidget->setCurrentIndex(1);
}
void personnel_click::on_pushButton_4_clicked()
{
mentionner();
ui->tableView->setColumnHidden(0,true);
arrow();
}
void personnel_click::on_pushButton_3_clicked()
{
reply
= QMessageBox::question(this,
"suppression de personnel",
"are you sure you want to delete this personnel?",
Personnel p ;
int i = ui->tableView->model()->index(ui->tableView->currentIndex().row(),0).data().toInt();
p.supprimer(i);
p.son_2();
on_pushButton_4_clicked();
}
}
void personnel_click::arrow()
{
int k = ui->tableView->currentIndex().row();
ui->label_9->setNum(k);
ui->label_9->update();
}
void personnel_click::on_pushButton_5_clicked()
{
QString horaire
=ui
->horaire
->text
();
//QString domaine=ui->domaine->text();
bool etat = 0;
//qrb->setChecked(false);
if( qrb ->isChecked())
etat = 1;
else etat=0 ;
if (etat==1)
dispo="disponible";
else dispo="indisponible";
QString dom
=ui
->comboBox
->currentText
();
int appresiation=5;
Personnel x(nom,horaire,etat,dispo,dom,prix,appresiation);
bool test=x.ajouterPersonnel();
if(test)
{
p.son();
}
else
{
}
ui->horaire->clear();
ui->nom->clear();
ui->nom->clear();
on_pushButton_4_clicked();
}
void personnel_click::mentionner()
{
request->prepare("SELECT * FROM PERSONNEL");
request->exec();
model->setQuery(*request);
model
->setHeaderData
(0, Qt
::Horizontal,
QObject::tr("ID_P"));
model
->setHeaderData
(1, Qt
::Horizontal,
QObject::tr("NOM"));
model
->setHeaderData
(2, Qt
::Horizontal,
QObject::tr("APPRESTATION_P"));
model
->setHeaderData
(3, Qt
::Horizontal,
QObject::tr("ETAT"));
model
->setHeaderData
(4, Qt
::Horizontal,
QObject::tr("HORAIRE_P"));
model
->setHeaderData
(5, Qt
::Horizontal,
QObject::tr("PRIX"));
model
->setHeaderData
(6, Qt
::Horizontal,
QObject::tr("DOMAINE"));
ui->tableView->setModel(model);
}
void personnel_click::on_pushButton_2_clicked()
{
ui->stackedWidget->setCurrentIndex(2);
}
void personnel_click::on_pushButton_6_clicked()
{
Personnel p ;
int i = ui->tableView->model()->index(ui->tableView->currentIndex().row(),0).data().toInt();
QString prix
=ui
->salaire_2
->text
();
QString horaire
=ui
->horaire_2
->text
();
bool etat = 0;
//qrb->setChecked(false);
if( qrb ->isChecked())
etat = 1;
else etat=0 ;
if (etat==1)
dispo="disponible";
else dispo="indisponible";
p.modifier(i,prix,horaire,dispo);
on_pushButton_4_clicked();
}
void personnel_click
::on_lineEdit_textChanged(const QString &arg1
) {
ui->text->setText(arg1);
q->prepare("SELECT * FROM PERSONNEL WHERE "+ui->comboBox_2->currentText()+" LIKE '"+arg1+"%'");
q->exec();
model->setQuery(*q);
model
->setHeaderData
(0, Qt
::Horizontal,
QObject::tr("ID_P"));
model
->setHeaderData
(1, Qt
::Horizontal,
QObject::tr("NOM"));
model
->setHeaderData
(2, Qt
::Horizontal,
QObject::tr("APPRESTATION_P"));
model
->setHeaderData
(3, Qt
::Horizontal,
QObject::tr("ETAT"));
model
->setHeaderData
(4, Qt
::Horizontal,
QObject::tr("HORAIRE_P"));
model
->setHeaderData
(5, Qt
::Horizontal,
QObject::tr("PRIX"));
model
->setHeaderData
(6, Qt
::Horizontal,
QObject::tr("DOMAINE"));
ui->tableView->setModel(model);
ui->tableView->setColumnHidden(0,true);
}
void personnel_click::on_pushButton_7_clicked()
{
bien b;
hide();
b.exec();
b.show();
}