PDA

View Full Version : segmentation fault!!



Yayati.Ekbote
24th March 2010, 11:07
Hi guys,

I am using old version of Qt which comes with the Friendly arm device for embedded development.
It consists of Qtopia 2.2.0 with Qt2 designer.

I prepared a small application for testing using a QListView. I drew ListView widget on my form which i named ListView and named ny UI file as myapp_base.ui.

In my header file i wrote-


#ifndef MYAPP_H
#define MYAPP_H

#include "myapp_base.h"

class MyApp : public MyAppBase
{
public:
MyApp(QWidget *parent=0,const char *name=0, WFlags fl=0);
~MyApp();

}

My implementation file is following-


#include "myapp.h"
#include <qlistview.h>

MyApp::MyApp(QWidget *parent, const char *name,WFlags fl):
MyAppBase(parent,name,fl)
{
QListViewItem *newItem;
newItem->setText(0,"newItem");
ListView->insertItem(newItem);
}

MyApp::~MyApp()
{
}

And my main file is-


#include "myapp.h"
#include <qapplication.h>

int main(int argc, char *argv[])
{
QApplication app(argc,argv);
MyApp *obj;
obj->show();

return app.exec();
}

My code gets compiled successfully but gives a runtime segmentation fault. What is the problem??

wysota
24th March 2010, 11:10
You didn't create the item, just a pointer to it.

Yayati.Ekbote
24th March 2010, 11:17
Ok, But then when i wrote main like this-


#include "myapp.h"
#include <qapplication.h>

int main(int argc, char *argv[])
{
QApplication app(argc,argv);
MyApp obj;
obj.show();

return app.exec();
}

It gave me following error-

error main.cpp.7.there is no call for MyApp::MyApp()
candidates for the call are MyApp::MyApp(QWidget *parent,const char *name, WFlags fl);
candidates to the call are MyApp::MyApp(const MyApp&);

Also when i tried this..


MyApp obj=new MyApp;
or

MyApp obj= new MyApp();
or

MyApp obj=new MyApp(ListView,"myapp");

it gave the same error!!!!

what to do???

wysota
24th March 2010, 12:53
The error was not in main() but in MyApp::MyApp().

Please do yourself a favour and refresh your C++ knowledge.

Yayati.Ekbote
24th March 2010, 16:10
Thanks very much...problem solved!!!:) :cool: