QTableWidget Operations over columns
-
Hi
You should check all pointer to QTableWidgetItem * before using them.
It might return NULL and u crash.Still if you place a break point and single step you should find the line that makes you crash.
-
@mrjj I think it is that line, where I convert a QtableWidgetItem to QString:
str1 = stagepulse_item->data(Qt::DisplayRole).toString();
The syntax is right, I dont know what is the real reason though.
-
@Abderaouf
It seems correct. You are getting a QVariant from data and call toString.
So when debugging it crash on this line? -
@Abderaouf said in QTableWidget Operations over columns:
I dont know what is the real reason though
probably
stagepulse_item
is a null pointeralso your logic does not work, at the moment the calculation is based on whether the last line, second column in m_ptable_ConvDesign is Y or N
-
@mrjj When I run it, it works until I click on the button and then It crashes even though all the data are input. when I take out this line, the button doesn't work when I click at it.
-
@Abderaouf
as @VRonin asks,
could stagepulse_item be NULL ? -
@VRonin how can I check if stagepulse_item is a null pointer??
I want to check the value of each line not only the last. I should probably add another for loop for the columns, right?? -
if ( ! stagepulse_item) {
qDebug () << "NULL !!!";
return;
}str1 = stagepulse_item->data(Qt::DisplayRole).toString();
...- I want to check the value of each line not only the last. I should probably add another for loop for the columns, right??
yes something like that. currently u loop m_ptable_ConvDesign first and set str1 but that should be checked
while u loop over the rows. So for a row if COL have Y/N then do it accordingly. -
I used the below and it worked fine:
QTableWidgetItem *stagepulse_item = ui->m_ptable_ConvDesign->item(row, 1);
if(stagepulse_item!=NULL)
{
str1 = stagepulse_item->data(Qt::DisplayRole).toString();
}Cheers;
-
Gents;
One more challenge. I am trying to create a menu in my QTabWidget using the below basic code:
void CFAdvisor::CreateMenu()
{
fileMenu = MenuBar().addMenu(tr("&File"));
fileMenu->addAction(actionExit);
fileMenu-> addAction(actionPrint);
helpMenu = MenuBar() ->addMenu(tr("&Help"));
helpMenu-> addAction(actionContent);
helpMenu-> addAction(actionAbout);}
I have a the error message though, it says the following:
C:\computing\Qt Designer\cfadvisor.cpp:488: error: 'menuBar' was not declared in this scope
fileMenu = menuBar()->addMenu(tr("&File"));
^Any advise on how to correct this error. this is the Qt version I have.
Cheers
-
Hi
Where is MenuBar() ?
if CFAdvisor is not a main window type then you need to create the MenuBar yourself if not already
added in Designer.http://www.codeprogress.com/cpp/libraries/qt/QMenuBarAddMenu.php