Results 1 to 20 of 23

Thread: dwarf issue

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2010
    Posts
    53
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: dwarf issue

    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.

  2. #2
    Join Date
    Oct 2007
    Location
    Grenoble, France
    Posts
    80
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: dwarf issue

    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 )

  3. #3
    Join Date
    Feb 2010
    Posts
    53
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: dwarf issue

    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: dwarf issue

    Quote Originally Posted by hollowhead View Post
    I need to pass data from the mytestdialog class to the spreadsheet class.
    You don't pass data to classes, you pass it to objects.
    You can have multiple objects of the same class. You need to reference the exact same Spreadsheet object you created earlier, you can't just declare a pointer to its class.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Oct 2007
    Location
    Grenoble, France
    Posts
    80
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: dwarf issue

    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:
    1. 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:
    1. (...)
    2. #include "spreadsheet.h"
    3. class MyTestDialog : public QDialog, public Ui::MyTestDialog {
    4. Q_OBJECT
    5. public:
    6. MyTestDialog( QWidget * parent = 0, Qt::WFlags f = 0, Spreadsheet *spr = 0);
    7. (...)
    8. private :
    9. Spreadsheet *spreadsheet;
    10. (...)
    To copy to clipboard, switch view to plain text mode 

    and then

    Qt Code:
    1. MyTestDialog::MyTestDialog( QWidget * parent, Qt::WFlags f, Spreadsheet *spr) {
    2. (...)
    3. spreadsheet = spr;
    4. }
    5.  
    6. (...)
    7.  
    8. void MyTestDialog::onCalc1() {
    9. if (spreadsheet) // Don't forget to check if spreadsheet is not null
    10. spreadsheet->tests();
    11. }
    To copy to clipboard, switch view to plain text mode 

    and then in the code where you want to run this dialog
    Qt Code:
    1. 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 )

  6. #6
    Join Date
    Oct 2009
    Posts
    151
    Thanks
    6
    Thanked 13 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: dwarf issue

    A Spreadsheet object needs to be created somewhere in the programme first
    Qt Code:
    1. Spreadsheet *spreadsheet = new Spreadsheet
    To copy to clipboard, switch view to plain text mode 
    although I would be inclined to call the object something else to prevent confusion with the class name.
    Got to keep the loonies on the path ...

  7. #7
    Join Date
    Feb 2010
    Posts
    53
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: dwarf issue

    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.

    QWidget: Must construct a QApplication before a QPaintDevice
    The reason is this code here which I placed in my spreadsheet.cpp code.

    Qt Code:
    1. 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:
    1. 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

    Qt Code:
    1. void MainWindowImpl::createMdiWindow(const QString &fileName)
    2. {
    3. Spreadsheet *spreadsheet = new Spreadsheet;
    4. QMdiSubWindow *subWindow = mdiArea->addSubWindow(spreadsheet);
    5. subWindow->show();
    6. if (!fileName.isEmpty()) {
    7. spreadsheet->load(fileName);
    8. statusBar()->showMessage(tr("File loaded"), 2000);
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 
    This then creates a mdi spreadsheet (tablewidget) window and sets up some formatting etc. Is there any way round this? Ta.
    Last edited by hollowhead; 13th May 2010 at 14:40. Reason: updated contents

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: dwarf issue

    I think it would be best if you learned a bit of C++ before starting with Qt.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Oct 2009
    Posts
    151
    Thanks
    6
    Thanked 13 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: dwarf issue

    JD2000 I made your changes (thanks) I get a crash so bad the program never appears.
    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.

    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 ...

  10. #10
    Join Date
    Oct 2009
    Posts
    151
    Thanks
    6
    Thanked 13 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: dwarf issue

    One of these might work

    Qt Code:
    1. #
    2. void MyTestDialog::onCalc1()
    3. #
    4. {
    5.  
    6. //QMdiArea->activeSubWindow->spreadsheet->tests(); // pass list into test function
    7. QMdiArea->activeSubWindow->tests(); // pass list into test function
    8.  
    9. }
    To copy to clipboard, switch view to plain text mode 
    Got to keep the loonies on the path ...

  11. #11
    Join Date
    Feb 2010
    Posts
    53
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: dwarf issue

    Thanks very much JD2000 will try it if it fails will redsign app, call on stack and do calcs after closing dialog. Thanks.

Similar Threads

  1. MS C++ issue
    By sepehr in forum Installation and Deployment
    Replies: 4
    Last Post: 29th December 2008, 23:45
  2. XML issue
    By jbpvr in forum Qt Programming
    Replies: 1
    Last Post: 25th August 2008, 13:01
  3. UI issue.
    By kaushal_gaurav in forum Qt Programming
    Replies: 2
    Last Post: 13th August 2008, 11:41
  4. ui_....h issue
    By stevey in forum Qt Programming
    Replies: 5
    Last Post: 27th November 2007, 04:54
  5. qt3 to qt4 - uic issue
    By hvengel in forum Qt Programming
    Replies: 10
    Last Post: 4th March 2007, 02:59

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.