#include "mytable.h"
MyTable::MyTable(QWidget *parent, const char *name) : QWidget(parent, name)
{
setGeometry(10, 10,520,360);
rows=20;
cols=4;
table = new QTable(rows, cols, this);
table->setGeometry(10,10,500,300);
savep = new QPushButton("Save" , this);
savep->setGeometry(10, 320, 500, 30);
QObject::connect(savep, SIGNAL( clicked() ), this, SLOT( slot_save() ));
}
MyTable::~MyTable()
{
}
void MyTable::slot_save()
{
QFile file("file.txt");
file.open(IO_WriteOnly);
QTextStream outStream(&file);
for(int i=0; i< table->numRows(); ++i)
{
for(int j=0; j< table->numCols(); ++j)
{
QString s;
s = table->text(i, j);
outStream << s << " ";
}
// eine Zeile weiter
outStream << endl;
}
}
main.cpp
[code]
#include <kcmdlineargs.h>
#include <kaboutdata.h>
#include <klocale.h>
#include "mytable.h"
static const char *description =
I18N_NOOP("MyTable");
// INSERT A DESCRIPTION FOR YOUR APPLICATION HERE
static KCmdLineOptions options[] =
{
{ 0, 0, 0 }
// INSERT YOUR COMMANDLINE OPTIONS HERE
};
int main(int argc, char *argv[])
{
KAboutData aboutData( "mytable", I18N_NOOP("MyTable"),
VERSION, description, KAboutData::License_GPL,
"(c) 2002, mapiox", 0, 0, "mapiox@unixboard.de");
aboutData.addAuthor("mapiox",0, "mapiox@unixboard.de");
KCmdLineArgs::init( argc, argv, &aboutData );
KCmdLineArgs::addCmdLineOptions( options ); // Add our own options.
KApplication a;
MyTable *mytable = new MyTable();
a.setMainWidget(mytable);
mytable->show();
return a.exec();
}