PDA

View Full Version : dwarf issue



hollowhead
11th May 2010, 11:48
I've created a custom dialog for varoius mathematical tests. The user can select a number of cells with the mouse which appears a linedit in the format Ax:Zx where x is a number. Or they can type in the aforementioned format. On pressing a calc button I wish to not close the dialog but calculate the answer in my spreadsheet class. I'm getting a
Scope for 1272:
Symbol strpos is a variable with complex or multiple locations (DWARF2), length 4.
Symbol list is a variable with complex or multiple locations (DWARF2), length 4.
Symbol prefix is a variable with complex or multiple locations (DWARF2), length 4.
Symbol this is a variable with complex or multiple locations (DWARF2), length 4.

Here's my code. I also tried passing by reference commented out below but this crashes at the setCurrentCell without the DWARF2. The problem is I don't know what DWARF means although I assume its some kind of memory allocation error. Can anyone tell me where I'm going wrong? Much thanks.

mydialog.h



class MyTestDialog : public QDialog, public Ui::MyTestDialog
{

Q_OBJECT

public:

MyTestDialog( QWidget * parent = 0, Qt::WFlags f = 0 );

private slots:

void onCalc1();
void on_lineEdit_textChanged();

private :

};



and its cpp file



#include "spreadsheet.h"

// start of dialog's constructor

Spreadsheet *spreadsheet; // to access spreadsheet class

MyTestDialog::MyTestDialog( QWidget * parent, Qt::WFlags f)
: QDialog(parent, f)
{
setupUi(this);

QRegExp regExp("[A-Za-z][1-9][0-9]{0,3}:[A-Za-z][1-9][0-9]{0,3}"); // works up to z9999 if you want more increase the 3
lineEdit->setValidator(new QRegExpValidator(regExp, this));

// signals slots to close or calculate dialog

connect(calcButton, SIGNAL(clicked()), this, SLOT(onCalc1()));
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));

}
// end of dialog's constructor

void MyTestDialog::on_lineEdit_textChanged()
{
calcButton->setEnabled(lineEdit->hasAcceptableInput());
}

void MyTestDialog::onCalc1()
{

//QString strpos = lineEdit->text();//.toUpper(); // put what is in linedit in string


// QStringList list1 = strpos.split(":", QString::SkipEmptyParts); // split parts before colon and remove colon put in list

spreadsheet->tests(); // pass list into test function
//spreadsheet->tests(list1); // pass list into test function
}



and the source in the spreadsheet class



void Spreadsheet::testDialog() // calls testdialog
{
// code for selectedCellRange goes here left out for reasons of space it works
if (!MyTestDialog) // check if dialog is loaded

MyTestDialog = new MyTestDialog(this); // if not create new instance

MyTestDialog->show(); // show as non-modal
MyTestDialog->raise();
MyTestDialog->activateWindow();
MyTestDialog->lineEdit->setText(selectedCellRange); // dumps current selected cell range as text in linedit

}

//void Spreadsheet::tests(const QStringList &list)
void Spreadsheet::tests()
{

QString strpos = MyTestDialog->lineEdit->text();//.toUpper(); // line 1272 put what is in linedit in string
QStringList list = strpos.split(":", QString::SkipEmptyParts);

QString prefix;
prefix=list[0];
setCurrentCell(prefix.mid(1).toInt() - 1,
prefix[0].unicode() - 'A');


}

JD2000
11th May 2010, 13:24
Dwarf is a debugging format used by the likes of GDB.


strpos is actually a C/C++ function for finding the position of a substring within a string.
Try using a different variable name.

hollowhead
11th May 2010, 14:41
Thanks for your suggestion JD2000 no change though......

wysota
11th May 2010, 15:16
So you changed your "strpos" variable to some other name and the program still complains about "strpos"?

hollowhead
11th May 2010, 17:25
No it crashes out and complains about that line. The name of the string is irrelevant I changed it all to "front".

JD2000
11th May 2010, 18:43
So it crashed this time, how about a back trace?

hollowhead
11th May 2010, 20:29
I tried this it basically tells me what I already knew....




Program received signal SIGSEGV, Segmentation fault.
0x08069da9 in Spreadsheet::tests (this=0x0) at src/spreadsheet.cpp:1272

1272 QString front = MyTestDialog->lineEdit->text();//.toUpper(); // put what is in linedit in string
(gdb)

wysota
11th May 2010, 21:52
That's not a backtrace, that's the current stack frame. I would guess you are accessing a null pointer. You can see "this" equals 0x0 (which is null).

hollowhead
11th May 2010, 22:28
wysota you are right. I know very little about using gdb from the command line which is what I did, I've just tried KDbg out of desperation really since I have found in the past it has given me very little info. This time it has been much more helpful. But why when my linedit is not empty does this happen?






ASSERT failure in QList<T>::operator[]: "index out of range", file /usr/include/qt4/QtCore/qlist.h, line 403


and




Cannot access memory at address 0x0

wysota
11th May 2010, 22:30
Please post a backtrace. You can print a backtrace by running the "bt" command from gdb after the application crashes. Be sure to build the application in debug mode.

hollowhead
12th May 2010, 09:34
Program received signal SIGSEGV, Segmentation fault.
0x08069da9 in Spreadsheet::tests (this=0x0) at src/spreadsheet.cpp:1272

1272 QString front = myTestDialog->lineEdit->text();//.toUpper(); // put what is in linedit in string
(gdb) bt
#0 0x08069da9 in Spreadsheet::tests (this=0x0) at src/spreadsheet.cpp:1272
#1 0x0806bc3d in mytTestDialog::onCalc1 (this=0x83322f8)
at src/myTestDialog.cpp:38
#2 0x0806d7b3 in myTestDialog::qt_metacall (this=0x83322f8,
_c=QMetaObject::InvokeMetaMethod, _id=0, _a=0xbfffd398)
at moc_myTestDialog.cpp:70
#3 0x00c21263 in QMetaObject::activate(QObject*, int, int, void**) ()
from /usr/lib/libQtCore.so.4
#4 0x00c216d8 in QMetaObject::activate(QObject*, QMetaObject const*, int, int, void**) () from /usr/lib/libQtCore.so.4
#5 0x008dbcc1 in QAbstractButton::clicked(bool) () from /usr/lib/libQtGui.so.4
#6 0x00604549 in ?? () from /usr/lib/libQtGui.so.4
#7 0x006061a4 in ?? () from /usr/lib/libQtGui.so.4
#8 0x00606431 in QAbstractButton::mouseReleaseEvent(QMouseEvent*) ()
from /usr/lib/libQtGui.so.4
#9 0x002a4012 in QWidget::event(QEvent*) () from /usr/lib/libQtGui.so.4
#10 0x006043ee in QAbstractButton::event(QEvent*) ()
from /usr/lib/libQtGui.so.4
#11 0x006ae66d in QPushButton::event(QEvent*) () from /usr/lib/libQtGui.so.4
#12 0x0024ef54 in QApplicationPrivate::notify_helper(QObject*, QEvent*) ()
from /usr/lib/libQtGui.so.4
#13 0x00257033 in QApplication::notify(QObject*, QEvent*) ()
from /usr/lib/libQtGui.so.4
14 0x00c0b6cb in QCoreApplication::notifyInternal(QObject*, QEvent*) ()
from /usr/lib/libQtCore.so.4
#15 0x00255f6e in QApplicationPrivate::sendMouseEvent(QWidget*, QMouseEvent*, QWidget*, QWidget*, QWidget**, QPointer<QWidget>&) () from /usr/lib/libQtGui.so.4
#16 0x002c47c0 in ?? () from /usr/lib/libQtGui.so.4
#17 0x002c3c4b in QApplication::x11ProcessEvent(_XEvent*) ()
from /usr/lib/libQtGui.so.4
#18 0x002f0502 in ?? () from /usr/lib/libQtGui.so.4
#19 0x01101e88 in g_main_context_dispatch () from /lib/libglib-2.0.so.0
#20 0x01105730 in ?? () from /lib/libglib-2.0.so.0
#21 0x01105863 in g_main_context_iteration () from /lib/libglib-2.0.so.0
#22 0x00c3602c in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/libQtCore.so.4
#23 0x002efbe5 in ?? () from /usr/lib/libQtGui.so.4
#24 0x00c09c79 in QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/libQtCore.so.4
#25 0x00c0a0ca in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) ()
from /usr/lib/libQtCore.so.4
#26 0x00c0c53f in QCoreApplication::exec() () from /usr/lib/libQtCore.so.4
#27 0x0024edd7 in QApplication::exec() () from /usr/lib/libQtGui.so.4
#28 0x08055b2a in main (argc=1, argv=0xbffff514) at src/main.cpp:10


Thanks for your interest wysota its not this is it?



// start of dialog's constructor

Spreadsheet *spreadsheet; // to access spreadsheet class


In the meanwhile I'm going uncomment the pass by reference code and see what backtrace I get from that.

JD2000
12th May 2010, 10:06
You do not appear to have a spreadsheet object, so as Wysota says, you are accessing a null pointer.

hollowhead
12th May 2010, 10:22
Yes but how do get round this, what code do I need to write? I need to pass data from the mytestdialog class to the spreadsheet class. Thanks.

calhal
12th May 2010, 12:16
mytestdialog must have a correct pointer to the spreadsheet, assuming this spreadsheet was created somewhere, for example in the mainwindow
You can make a pointer to the spreadsheet class a member of your dialog class and then initialize it by passing a pointer to the constructor of this dialog or via a setter method (which you have to define) just after creating mytestdialog and before executing it.

hollowhead
13th May 2010, 10:48
calhal,

I accept what you say and I've read your post very carefully, I've looked in my C++ books and online but I haven't a clue how to do this. I've tried several things including making my Spreadsheet class a friend of my dialog class (compiles but same error) and several other methods but these wouldn't compile. I would be very grateful if you could post some code or a link to a tutorial that shows this since I'm really stuck here.... Ta.

wysota
13th May 2010, 11:06
I need to pass data from the mytestdialog class to the spreadsheet class.
You don't pass data to classes, you pass it to objects.
You can have multiple objects of the same class. You need to reference the exact same Spreadsheet object you created earlier, you can't just declare a pointer to its class.

calhal
13th May 2010, 13:41
I've just noticed that you're creating and executing this dialog in spreadsheet so you have already passed the pointer to spreadsheet to the dialog here:

MyTestDialog = new MyTestDialog(this);

you can access public members of spreadsheet through parent-> within your dialog

But to show you what I wrote before:


(...)
#include "spreadsheet.h"
class MyTestDialog : public QDialog, public Ui::MyTestDialog {
Q_OBJECT
public:
MyTestDialog( QWidget * parent = 0, Qt::WFlags f = 0, Spreadsheet *spr = 0);
(...)
private :
Spreadsheet *spreadsheet;
(...)


and then



MyTestDialog::MyTestDialog( QWidget * parent, Qt::WFlags f, Spreadsheet *spr) {
(...)
spreadsheet = spr;
}

(...)

void MyTestDialog::onCalc1() {
if (spreadsheet) // Don't forget to check if spreadsheet is not null
spreadsheet->tests();
}


and then in the code where you want to run this dialog


dialog = new MyTestDialog(this, 0, pointer_to_spreadsheet)

JD2000
13th May 2010, 13:53
A Spreadsheet object needs to be created somewhere in the programme first
Spreadsheet *spreadsheet = new Spreadsheet although I would be inclined to call the object something else to prevent confusion with the class name.

hollowhead
13th May 2010, 14:37
Wsoyta you are of course right, I do find this business of objects coming from C confusing. JD2000 I made your changes (thanks) I get a crash so bad the program never appears.


QWidget: Must construct a QApplication before a QPaintDevice

The reason is this code here which I placed in my spreadsheet.cpp code.



Spreadsheet *spreadsheet1 = new Spreadsheet;


Since adding Spreadsheet *spreadsheet1; in the spreadsheet.cpp file runs but has a null pointer again.

and using



myTestDialog = newmyTestDialog(this, 0, spreadsheet1);


I assume the problem is my application is an mdi app so I have a mainwindow class that does this




void MainWindowImpl::createMdiWindow(const QString &fileName)
{
Spreadsheet *spreadsheet = new Spreadsheet;
QMdiSubWindow *subWindow = mdiArea->addSubWindow(spreadsheet);
subWindow->show();
if (!fileName.isEmpty()) {
spreadsheet->load(fileName);
statusBar()->showMessage(tr("File loaded"), 2000);
}
}


This then creates a mdi spreadsheet (tablewidget) window and sets up some formatting etc. Is there any way round this? Ta.

wysota
13th May 2010, 14:52
I think it would be best if you learned a bit of C++ before starting with Qt.

JD2000
13th May 2010, 15:01
JD2000 I made your changes (thanks) I get a crash so bad the program never appears.
What changes would those be? I simply pointed out that you did not have a spreadsheet object, presumably because it was renamed spreadsheet1. See line #0 in your back trace.

Generally you can not call object functions when the object does not exist.

JD2000
14th May 2010, 19:32
One of these might work


#
void MyTestDialog::onCalc1()
#
{

//QMdiArea->activeSubWindow->spreadsheet->tests(); // pass list into test function
QMdiArea->activeSubWindow->tests(); // pass list into test function

}

hollowhead
17th May 2010, 09:27
Thanks very much JD2000 will try it if it fails will redsign app, call on stack and do calcs after closing dialog. Thanks.