because your model is destroyed at the end of the function.
if you put ui->listView->setModel(new TarefaModel(5, this));
does it work ?
because your model is destroyed at the end of the function.
if you put ui->listView->setModel(new TarefaModel(5, this));
does it work ?
plopes21 (2nd May 2012)
Your code worked.
I have another problem. When I click on the pushbutton 'Add Task' will want to add a task list that is declared in taskModel.
I have this code but does not work ...
Qt Code:
void MainWindow::on_addTarefa_clicked() { Task t1(ui->lineNameTask->text()); // t1.setContext(ui->LineContext->text()); // t1.setProject(ui->lineProject->text()); TaskModel model(5); model.addTask(t1); // TaskModel::taskList.push_back(t1); }To copy to clipboard, switch view to plain text mode
Qt Code:
void TaskModel::addTask(const Task &task){ qDebug("hello"); // taskList<< task; taskList.push_back(task); endInsertRows(); }To copy to clipboard, switch view to plain text mode
same thing here.
you need to control the life of your objects:
if you write:
{
TarefaModel model(5);
//it lives
}
//it s dead
so in your exemple you create a whole new model add an item to it and the it is destroyed at the end of your function
1) why do you recreate a new model every time : create one model and control the content is way better.
2) if you need to create your models use new and pass this as the parent so it will be destroyed by the parent
plopes21 (2nd May 2012)
I managed to add.
Now I am working with QAbstractItemDelegate.
I want to use this item that I did:
item.jpg
I really have to use QAbstractItemDelegate?
How do I set up my item with QAbstractItemDelegate?
Thanks
Last edited by plopes21; 2nd May 2012 at 17:19.
i think it s the way but i don't know much about delegates (i switched to QML it is way easier for that)
but this exemple sould help you:
http://qt-project.org/doc/qt-4.8/ite...rdelegate.html
plopes21 (2nd May 2012)
I'll try to solve this problem and will post here some questions that will arise.
Thanks Le_B
How can I put a distance between the margin items?
I like this:
itemsn.jpg
answer me please.
Hi plopes21,
I think you need to add Vertical Layout to all those labels in tarefaWidget.ui.
I am working something quite close to what you are doing and would you mind to upload your project files to have a look on how you put everything into one piece?
Thanks
Bookmarks