Yes but how do get round this, what code do I need to write? I need to pass data from the mytestdialog class to the spreadsheet class. Thanks.
Yes but how do get round this, what code do I need to write? I need to pass data from the mytestdialog class to the spreadsheet class. Thanks.
mytestdialog must have a correct pointer to the spreadsheet, assuming this spreadsheet was created somewhere, for example in the mainwindow
You can make a pointer to the spreadsheet class a member of your dialog class and then initialize it by passing a pointer to the constructor of this dialog or via a setter method (which you have to define) just after creating mytestdialog and before executing it.
Last edited by calhal; 12th May 2010 at 12:17. Reason: spelling corrections
You have to run a level 3 diagnostic.
Ashes to ashes, Qt to Qt ( wysota )
calhal,
I accept what you say and I've read your post very carefully, I've looked in my C++ books and online but I haven't a clue how to do this. I've tried several things including making my Spreadsheet class a friend of my dialog class (compiles but same error) and several other methods but these wouldn't compile. I would be very grateful if you could post some code or a link to a tutorial that shows this since I'm really stuck here.... Ta.
I've just noticed that you're creating and executing this dialog in spreadsheet so you have already passed the pointer to spreadsheet to the dialog here:
Qt Code:
MyTestDialog = new MyTestDialog(this);To copy to clipboard, switch view to plain text mode
you can access public members of spreadsheet through parent-> within your dialog
But to show you what I wrote before:
Qt Code:
(...) #include "spreadsheet.h" Q_OBJECT public: (...) private : Spreadsheet *spreadsheet; (...)To copy to clipboard, switch view to plain text mode
and then
Qt Code:
(...) spreadsheet = spr; } (...) void MyTestDialog::onCalc1() { if (spreadsheet) // Don't forget to check if spreadsheet is not null spreadsheet->tests(); }To copy to clipboard, switch view to plain text mode
and then in the code where you want to run this dialog
Qt Code:
dialog = new MyTestDialog(this, 0, pointer_to_spreadsheet)To copy to clipboard, switch view to plain text mode
You have to run a level 3 diagnostic.
Ashes to ashes, Qt to Qt ( wysota )
A Spreadsheet object needs to be created somewhere in the programme firstalthough I would be inclined to call the object something else to prevent confusion with the class name.Qt Code:
Spreadsheet *spreadsheet = new SpreadsheetTo copy to clipboard, switch view to plain text mode
Got to keep the loonies on the path ...
Wsoyta you are of course right, I do find this business of objects coming from C confusing. JD2000 I made your changes (thanks) I get a crash so bad the program never appears.
The reason is this code here which I placed in my spreadsheet.cpp code.QWidget: Must construct a QApplication before a QPaintDevice
Qt Code:
Spreadsheet *spreadsheet1 = new Spreadsheet;To copy to clipboard, switch view to plain text mode
Since adding Spreadsheet *spreadsheet1; in the spreadsheet.cpp file runs but has a null pointer again.
and using
Qt Code:
myTestDialog = newmyTestDialog(this, 0, spreadsheet1);To copy to clipboard, switch view to plain text mode
I assume the problem is my application is an mdi app so I have a mainwindow class that does this
This then creates a mdi spreadsheet (tablewidget) window and sets up some formatting etc. Is there any way round this? Ta.Qt Code:
{ Spreadsheet *spreadsheet = new Spreadsheet; QMdiSubWindow *subWindow = mdiArea->addSubWindow(spreadsheet); subWindow->show(); if (!fileName.isEmpty()) { spreadsheet->load(fileName); statusBar()->showMessage(tr("File loaded"), 2000); } }To copy to clipboard, switch view to plain text mode
Last edited by hollowhead; 13th May 2010 at 14:40. Reason: updated contents
What changes would those be? I simply pointed out that you did not have a spreadsheet object, presumably because it was renamed spreadsheet1. See line #0 in your back trace.JD2000 I made your changes (thanks) I get a crash so bad the program never appears.
Generally you can not call object functions when the object does not exist.
Last edited by JD2000; 13th May 2010 at 15:06.
Got to keep the loonies on the path ...
One of these might work
Qt Code:
# void MyTestDialog::onCalc1() # { //QMdiArea->activeSubWindow->spreadsheet->tests(); // pass list into test function QMdiArea->activeSubWindow->tests(); // pass list into test function }To copy to clipboard, switch view to plain text mode
Got to keep the loonies on the path ...
Thanks very much JD2000 will try it if it fails will redsign app, call on stack and do calcs after closing dialog. Thanks.
Bookmarks