Ok, now it able to save the data using menu option save. But, on second time opening table is crashing,
before entering the data in table cells. Debug attach.
string-error.jpg
Ok, now it able to save the data using menu option save. But, on second time opening table is crashing,
before entering the data in table cells. Debug attach.
string-error.jpg
The screenshot is useless. All it says is that the debugger is looking for qstring.cpp and can't find it.
You need to run your program in the debugger, set a breakpoint where you "open the table" (whatever that means) and step through the code until you see the cause of the crash.
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
That screen shot is raised during debugging using debugger.
After setCentralWidget, that screen raised.Qt Code:
MainWindow::MainWindow() { } void MainWindow::newFile() { //Set table row count 4 and column count 5 m_table->setRowCount(4); m_table->setColumnCount(5); QFont font; font.setBold(true); font.setStyleName("Arial"); //Add Table items here m_table->item(0, 0)->setFont(font); m_table->item(1, 0)->setFont(font); m_table->item(2, 0)->setFont(font); m_table->item(3, 0)->setFont(font); m_table->verticalHeader()->hide(); m_table->horizontalHeader()->hide(); setCentralWidget(m_table); }To copy to clipboard, switch view to plain text mode
Last edited by marvic_44; 31st December 2016 at 04:21.
Move this
Qt Code:
setCentralWidget(m_table);To copy to clipboard, switch view to plain text mode
to the constructor, and modify the constructor like this:
Qt Code:
{ setCentralWidget(m_table); }To copy to clipboard, switch view to plain text mode
And in the newFile() slot, call "m_table->clearContents()" before adding new items to the table. If all of your items have the same font, then you can call setFont() on the table when you create it in the constructor and all new items wil inherit that setting.
I don't know what else you are doing wrong, but I am guessing you are still not doing enough error checking to see that the pointers you are getting are valid before using them.
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
If the menu options, except new and save are disabled , it is not crashing. If it reversed it, works fine. (disabling new and save, enable other options)
All the other menu options do display some data, it means "setCentralWidget()" function is called in all the options (slots) to display the data.
I think this will not work properly. Unless if there a function to deactivate the central widget. before or after entering into the new slots.
Thanks for help.
No, this idea is completely wrong. You do not seem to understand the purpose of this function. It is not to load data into the table, it is to tell QMainWindow that the QTableWidget is the main widget in the application window, and that all of the other widgets (menu, toolbar, dock widgets, etc.) are to be laid out around it. As I showed in the last post, you should call the method once, when you construct the main window, not every time you want to update the table. At the same time, you also make the connections between signals and slots for the menu items, table, and whatever other GUI elements you have that need to talk to each other. You do this once, in the MainWindow constructor.it means "setCentralWidget()" function is called in all the options (slots) to display the data.
The fact that you can do random things with your menus and it causes crashes tells me that you have memory bugs in a large part of your code, once again probably due to using pointers that are not valid. It could be due to uninitialized pointers, pointers to objects that have been deleted, or failing to check that a pointer returned by some other function is not NULL before you use it. It could also be due to trying to access an element of an array that is out-of-bounds, but in your case I think it is probably trying to use a bad pointer.
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
What i mean to say is, "setCentralWidget()" this function is used in all the menu options (slots). Not in particular function or slots.
Switching between the menu options work fine only when i do not press new and save menu options which deals with QtableWidget.
or
If other options are disable and except new and save options works fine, means table created and data stored in file properly.
When i switch between all the options, it crashes when back to new option ie QTableWidget.
This kind features worked fine before, One option for widgets other options for different displays and saving data etc. Even i remember worked perfectly in Symbian S60 and UIQ.
Last edited by marvic_44; 2nd January 2017 at 17:46.
Yes, and that is completely wrong. It should be used once in the MainWindow constructor.What i mean to say is, "setCentralWidget()" this function is used in all the menu options (slots). Not in particular function or slots.
Sorry, you obviously are not interested in learning from me how to fix your program to make it correct and not crash. Maybe someone else will be more interested in helping you. Good luck.
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
Please read QMainWindow documentation, understand the layout used by Qt and the purpose of setCentralWidget(). And follow the suggestions of d_stranz.
Bookmarks