admkrk
27th April 2014, 04:03
Hi, First off let me apologize if this doesn't make much sense at first.
I might just be going about this all wrong, but I'm trying to have a second window open and use that for getting input. What I have works OK until I try to send the result back to the main window.
gui is my main class(QMainWindow) and list(QWidget) is my second class that opens when list_button is clicked.
void gui::on_list_btn_clicked()
{
list *mileage_list = new list;
mileage_list->populate_list(mileage);
mileage_list->show();
}
populate_list() works fine also as expected.
void list::populate_list(QVector<Entry> mileage)
{
QString list_item;
QString format_date;
ui->listWidget->addItem("Date Miles Gallons");
for(int i = 0; i < mileage.size(); ++i)
{
for(int j = 0; j < mileage[i].date.length(); ++j)
{
format_date.append(mileage[i].date[j]);
if(j == 1 || j == 3)
{
format_date.append("/");
}
}
list_item = format_date % " "
% QString::number(mileage[i].miles) % " "
% QString::number(mileage[i].gallons);
ui->listWidget->addItem(list_item);
format_date = "";
}
}
I could just add the QListWidget to the main window, but I'd rather have it a separate window to save space in the main one. The way its supposed to work is to let the user select a date from the list and pass the index back to the main window which obviously doesn't work as I have it.
void list::on_listWidget_itemClicked(QListWidgetItem *item)
{
int start_index = ui->listWidget->row(item);
//gui->set_index(start_index);
}
void gui::set_index(int index)
{
ui->start_date_txtBox->setText(mileage[index].date);
}
Besides the problem of sending the index back(I feel like I'm tripping over a crack in the sidewalk here), I don't like that the list needs to be closed separately and it should close with the main window if not done so first. Can someone suggest either a way to make this work as is or where I should look to get it working more efficiently. If I left something out(which I probably did), just let me know and I'll fill in the gaps.
Thanks
I might just be going about this all wrong, but I'm trying to have a second window open and use that for getting input. What I have works OK until I try to send the result back to the main window.
gui is my main class(QMainWindow) and list(QWidget) is my second class that opens when list_button is clicked.
void gui::on_list_btn_clicked()
{
list *mileage_list = new list;
mileage_list->populate_list(mileage);
mileage_list->show();
}
populate_list() works fine also as expected.
void list::populate_list(QVector<Entry> mileage)
{
QString list_item;
QString format_date;
ui->listWidget->addItem("Date Miles Gallons");
for(int i = 0; i < mileage.size(); ++i)
{
for(int j = 0; j < mileage[i].date.length(); ++j)
{
format_date.append(mileage[i].date[j]);
if(j == 1 || j == 3)
{
format_date.append("/");
}
}
list_item = format_date % " "
% QString::number(mileage[i].miles) % " "
% QString::number(mileage[i].gallons);
ui->listWidget->addItem(list_item);
format_date = "";
}
}
I could just add the QListWidget to the main window, but I'd rather have it a separate window to save space in the main one. The way its supposed to work is to let the user select a date from the list and pass the index back to the main window which obviously doesn't work as I have it.
void list::on_listWidget_itemClicked(QListWidgetItem *item)
{
int start_index = ui->listWidget->row(item);
//gui->set_index(start_index);
}
void gui::set_index(int index)
{
ui->start_date_txtBox->setText(mileage[index].date);
}
Besides the problem of sending the index back(I feel like I'm tripping over a crack in the sidewalk here), I don't like that the list needs to be closed separately and it should close with the main window if not done so first. Can someone suggest either a way to make this work as is or where I should look to get it working more efficiently. If I left something out(which I probably did), just let me know and I'll fill in the gaps.
Thanks