![]() Registered Member ![]()
|
I think I've tried a similar approach earlier, because I'm getting the same errors now as I got then. I didn't post my main.cpp code earlier, but this is where the errors start now. Understandably, because MainWindow should be called with two arguments this way, only I'm not sure what to pass in main.cpp:
main.cpp:
This is the error:
Other errors crop up in mainwindow.cpp:
And datamodel.cpp:
Last edited by mensch on Thu Apr 09, 2009 11:35 pm, edited 1 time in total.
I have forced myself to contradict myself in order to avoid conforming to my own taste. Marcel Duchamp
|
![]() Administrator ![]()
|
You have two choices really:
1: Make main.cpp create DataModel, which will then create the MainWindow. 2: Make main.cpp create MainWindow, which will create the DataModel. Regarding error in datamodel.cpp, oops my mistake. It should have been this:
Also, try this for a constructor:
KDE Sysadmin
[img]content/bcooksley_sig.png[/img] |
![]() Registered Member ![]()
|
I think option two is the best one. Create the mainwindow first and then populate it seems more logical.
When I put dataModel* parentModel = dataModel(this) in the constructor I get the error that you can't use "this" in this context. There are other errors, but we're down to 9 instead of 21. ![]()
Last edited by mensch on Fri Apr 10, 2009 9:17 am, edited 1 time in total.
I have forced myself to contradict myself in order to avoid conforming to my own taste. Marcel Duchamp
|
![]() Administrator ![]()
|
Given your choice.....
The MainWindow constructor no longer requires DataModel in it:
The DataModel constructor needs to mention MainWindow now:
You can fix the forbids declaration.... error by adding the following line around the top of datamodel.h:
KDE Sysadmin
[img]content/bcooksley_sig.png[/img] |
![]() Registered Member ![]()
|
I think I'm still doing something wrong. Sorry.
![]() Have I missed something in the declarations below? I get the following errors: datamodel.cpp:31: error: prototype for 'dataModel::dataModel(MainWindow*)' does not match any in class 'dataModel' error: dataModel::dataModel() error: candidates are: dataModel::dataModel(const dataModel& ) datamodel.h:37: error: expected `)' before '*' token mainwindow.cpp:
datamodel.cpp:
datamodel.h:
I have forced myself to contradict myself in order to avoid conforming to my own taste. Marcel Duchamp
|
![]() Administrator ![]()
|
You need to add this to datamodel.h:
KDE Sysadmin
[img]content/bcooksley_sig.png[/img] |
![]() Registered Member ![]()
|
Thanks again! Everything seems to work perfectly now. No errors and I'm able to access the things I want.
Thanks bcooksley and anda_skoa for all the help.
I have forced myself to contradict myself in order to avoid conforming to my own taste. Marcel Duchamp
|
![]() Registered Member ![]()
|
Back again with a related question. Is it possible to use slots defined in the datamodel class in the mainwindow class or is it considered bad practice?
I have forced myself to contradict myself in order to avoid conforming to my own taste. Marcel Duchamp
|
![]() Administrator ![]()
|
It is completely acceptable to use a childs signals / slots to do something, I tend to avoid using a parents signals / slots however.
KDE Sysadmin
[img]content/bcooksley_sig.png[/img] |
![]() Registered Member ![]()
|
I'm sure I'm pointing to the wrong object again, because I get these warnings when declaring the slot like this. "model" is the publicly available dataModel class declared in mainwindow.h:
Warning:
Data model is declared like this:
I have forced myself to contradict myself in order to avoid conforming to my own taste. Marcel Duchamp
|
![]() Administrator ![]()
|
You need to connect to it like so, since the mainWindow owns the object you are connecting to.
connect(clientList, SIGNAL(itemClicked(QTreeWidgetItem*, int)), mainWindow->model, SLOT(updateProjectData(QTreeWidgetItem*)));
KDE Sysadmin
[img]content/bcooksley_sig.png[/img] |
![]() Registered Member ![]()
|
mainWindow is only declared in datamodel.h, so I get an error on scope declaration. I'm calling the connect in mainwindow.cpp, while the slot function is in datamodel.cpp.
I have forced myself to contradict myself in order to avoid conforming to my own taste. Marcel Duchamp
|
![]() Administrator ![]()
|
Oops. I misread the post. I should have put:
connect(clientList, SIGNAL(itemClicked(QTreeWidgetItem*, int)), dataModel->model, SLOT(updateProjectData(QTreeWidgetItem*)));
KDE Sysadmin
[img]content/bcooksley_sig.png[/img] |
![]() Registered Member ![]()
|
Tried that one as well.
![]()
It's being declared like this in mainwindow.h:
And called in mainwindow.cpp:
I have forced myself to contradict myself in order to avoid conforming to my own taste. Marcel Duchamp
|
![]() Administrator ![]()
|
Maybe try this instead:
connect(clientList, SIGNAL(itemClicked(QTreeWidgetItem*, int)), model->(**name of item as specified in ui file**), SLOT(updateProjectData(QTreeWidgetItem*))); Make sure to replace the entire (**name of item as specified in ui file**) with what is supposed to be there
Last edited by bcooksley on Wed Apr 15, 2009 8:43 pm, edited 1 time in total.
KDE Sysadmin
[img]content/bcooksley_sig.png[/img] |
Registered users: Bing [Bot], Google [Bot], Sogou [Bot]