inserting a row in a QTableWidget doesn t work!
Hi everybody,
i want to insert a row in QTableWidget with a buttonclick.
Code:
{
Q_OBJECT
public:
CoordinateTable
(QWidget *parent
=0);
private slots :
void addrow();
};
CoordinateTable
::CoordinateTable(QWidget *parent
){ setColumnCount(2);
setRowCount(2);
};
void CoordinateTable::addrow()
{
int row = CoordinateTable::rowCount();
CoordinateTable:: insertRow(row);
};
In main
Code:
....
CoordinateTable *tableWidget = new CoordinateTable;
QObject::connect(okbutton,
SIGNAL(clicked
()),
tableWidget ,SLOT(addrow()));
okbutton is a QT4 QPushButton.
Nothing happens when i click the button and i dont understand why.:confused:
Re: inserting a row in a QTableWidget doesn t work!
What happens if you add "qApp->aboutQt();" to CoordinateTable::addrow()?
Re: inserting a row in a QTableWidget doesn t work!
Hi jacek,Thanks for your reply.
If you mean like that:
Code:
void CoordinateTable::addrow()
{
int row = CoordinateTable::rowCount();
CoordinateTable::insertRow(row);
qApp->aboutQt();
};
it doesnt work too!
Re: inserting a row in a QTableWidget doesn t work!
Quote:
Originally Posted by
adonis
it doesnt work too!
Does "doesn't work" mean that the application runs, but it doesn't show the "About Qt" window when you click the button?
Re: inserting a row in a QTableWidget doesn t work!
Quote:
Originally Posted by
jacek
Does "doesn't work" mean that the application runs, but it doesn't show the "About Qt" window when you click the button?
Yes, that´s what i mean!
Re: inserting a row in a QTableWidget doesn t work!
Add "CONFIG += console" to your .pro file, re-run qmake and make and see whether there are no error messages on the console.
How do you initialize okbutton?
Re: inserting a row in a QTableWidget doesn t work!
Is the class declaration in a header file and listed in .pro?
Re: inserting a row in a QTableWidget doesn t work!
I don t see any errors on the console;
The initialization of the okbutton is:
Re: inserting a row in a QTableWidget doesn t work!
Do you add your button to a layout? Because I don't see creating it with a parent, and if you don't add it to a layout, I'm not sure any signals will work?
Does connect says anything in the debug console?
Regards
Re: inserting a row in a QTableWidget doesn t work!
it works now!:) i ve included a .moc file(i don t really understand how this works) and now every thing is OK.
Thank you guys!
Re: inserting a row in a QTableWidget doesn t work!
Quote:
Originally Posted by
adonis
i ve included a .moc file(i don t really understand how this works) and now every thing is OK.
That .moc file, among other things, contains the code that implements the signals and slots mechanism for your class. If you won't link your application with it, signals and slots won't work for your class. To avoid such problems in future, you should use qmake, CMake or any other build system, that understands Qt needs.
Re: inserting a row in a QTableWidget doesn t work!
Thanks jacek for the explanation.Actually ,i am using qmake.Should I use the moc file each time i want to define Signals or Slots in a class??
Re: inserting a row in a QTableWidget doesn t work!
Quote:
Originally Posted by
adonis
Actually ,i am using qmake.Should I use the moc file each time i want to define Signals or Slots in a class??
If you use qmake, then there are two things to remember:
- you have to re-run qmake after you add or remove Q_OBJECT macro to a class definition,
- if a class definition with Q_OBJECT is placed in a .cpp file instead of a header file, you have to add #include "filename.moc" at the end of that file and re-run qmake.