PDA

View Full Version : Application crashes at launch-time



Salazaar
12th June 2007, 14:42
Hi. I've got a problem. When I try to launch my application, it crashes. It compiled well, everything should be ok, but it isn't. Here's my api:
http://download.yousendit.com/F778F45E2CBBB92B
I really don't know why application sometimes crash at launch-time. Regards:confused:

high_flyer
12th June 2007, 14:45
why application sometimes crash at launch-time (i read it lunch-time)
maybe it doesn't like whats on the menu :p

just kidding.

steg90
12th June 2007, 14:47
You tried to debug this?! I'd first comment the connects out and see what happens...

Salazaar
12th June 2007, 15:03
How can I debug it if I don't have configured IDE with Qt, and I'm using it just to making code?

high_flyer
12th June 2007, 15:09
When I try to launch my application
from this it sounds like it is YOUR application, as in, you programmed it.
Is it so, or are you just a user of this program?

Salazaar
12th June 2007, 15:11
No, I programmed this application.

high_flyer
12th June 2007, 15:14
No, I programmed this application.
So where is the problem in debugging it?
If you can build it, you can debug it.
Either with debug messages or with a debuger.
You don't need a Qt configured IDE for that.

Salazaar
12th June 2007, 15:21
OK, so, how to debug it? I looked at the Assistant and typed make all instead of make, and reached:
C:\Dev-Cpp\bin\...\mingw32\...ld.exe cannot find -lqtmaind
I don't know is it this what you were asking about. If not, how to debug it?
edit:
executable was made - this was problem which appeared after building

wysota
12th June 2007, 15:53
Here's my api:
http://download.yousendit.com/F778F45E2CBBB92B

Please don't use external sites for showing images. Use the attachment feature of the forum. And don't use rar as the compressor but rather use some (g)zip variant if you really have to compress the image.

high_flyer
12th June 2007, 15:56
Please don't use external sites for showing images.
The link was an image??
I thought it was the project...

EDIT:
It is the project.

wysota
12th June 2007, 15:59
The link was an image??
I thought it was the project...

I don't know, I didn't open it, I hate RAR :) Anyway my comment applies to project files as well.

high_flyer
12th June 2007, 16:02
does the program crash every time, or just some times - this should crash every time.
Pardon me - this should not even compile!
I see you use 'ui' variable, yet you access GUI elements (which are not declered in the scope of your class) directly.
Look, I don't like answering like that, but you are really an extreme case.
Stop posting such questions.
You don't know C++, which is nothing to be ashamed of, but you can't expect us to waist our time to see the trivial mistakes you are making, and then teach you why they are a mistake.
Lern C++ first, then post your questions here.
This forum is NOT a C++ learning forum, there are many others on the net that do that.

wysota
12th June 2007, 16:21
does the program crash every time, or just some times - this should crash every time.
Pardon me - this should not even compile!
I see you use 'ui' variable, yet you access GUI elements (which are not declered in the scope of your class) directly.
Look, I don't like answering like that, but you are really an extreme case.
Stop posting such questions.
You don't know C++, which is nothing to be ashamed of, but you can't expect us to waist our time to see the trivial mistakes you are making, and then teach you why they are a mistake.
Lern C++ first, then post your questions here.
This forum is NOT a C++ learning forum, there are many others on the net that do that.

Syntax error on "waist" - verb expected
Syntax error on "Lern" - unknown token
;)

high_flyer
12th June 2007, 16:25
hehe... I stand corrected.
But only two typos is not that bad, relative to other posts....
The problem is, that my fingers often type what they want, specially if I type fast.

Salazaar
12th June 2007, 16:43
does the program crash every time, or just some times - this should crash every time.
Pardon me - this should not even compile!
I see you use 'ui' variable, yet you access GUI elements (which are not declered in the scope of your class) directly.


?? I've got Dialog class which inherits ui::Dialog, where are those declarations! And the function where are they used is part of this class!:confused:

high_flyer
12th June 2007, 16:49
Yes you are confused becasue you don't know C++.
But we can't help you with that, or at least, I don't have the time for it.

Salazaar
12th June 2007, 16:52
So I have to work at classes subject in my book...Maybe I'll understand...

high_flyer
12th June 2007, 17:03
That is a good way to go about it.
You can ask specifc C++ questions that you don't understand in the General Programming section in this forum.

Salazaar
12th June 2007, 17:13
And one more thing, in one of examples in C++ GUI Programming book, form was created by designer and one of command was groupBox->hide(); and it worked

high_flyer
12th June 2007, 17:16
what is the question?

Salazaar
12th June 2007, 17:21
This is access to GUI element, as you said. My code (subclassing) looks almost the same, and it doesn't work, because I have wrong GUI element access.
p.s.
I changed contents of my main.cpp file (it was wrong code in it) and it works.
edit. I mean that it doesn't crash, window is displayed but with no functionality. If I added ui. prefix in refering to GUI element would it be ok?

high_flyer
12th June 2007, 17:24
yes - but then you will stumble on the next error, and you wont understand why.
This is no way to learn C++.
Do it properly from the start.

Salazaar
12th June 2007, 17:27
Sure, I'll read classes chapter in C++ Symphony (Symfonia C++)

Salazaar
12th June 2007, 17:41
But there still is a problem. I added .ui prefix in every reference to gui element e.g. ui.convertButton->hide(); instead of convertButton->hide(); But it still doesn't have functionality. Did I miss something?

high_flyer
12th June 2007, 18:08
But there still is a problem.
Which is exactlxy what I said in my last post:


yes - but then you will stumble on the next error, and you wont understand why.
This is no way to learn C++.
Do it properly from the start.

Salazaar
12th June 2007, 18:33
;)Of course, you're right:)

Salazaar
12th June 2007, 18:50
Now I understand why do we have to use .ui prefix. Because in main cpp before creating dialog we define Ui::Dialog ui; where ui is a variable of the class in which is setupUi so that we have to call ui prefix to refer content of setupUi class. Is that right?

high_flyer
12th June 2007, 19:10
Well, yes and no.
Yes - but its not a "prefix".
Its an object, which has elements, and that is the way you reference elements of objects in C++.
But as you see, once you started reading a bit, things get much clearer.
Continue so.:cool:

You don't have to post here each time you learn a new C++ concept, we know them already ;)

You are welcome to ask specific question in the General Programming sections any time though.

Salazaar
12th June 2007, 19:25
I read classes chapter of my book and I think that there's something wrong with calling just e.g. hide():

ui.convertButton->hide();
But I don't know what. ;)
edit:
or maybe no. In docs it was something like this:

ui.colorDepthCombo->addItem(tr("2 colors (1 bit per pixel)"));
Could you tell me, what's wrong? I understand classes, but don't know why application doesn't have any functionality (the only working thing is exit button which closes dialog. But connection was made in designer)

high_flyer
12th June 2007, 20:13
provided that 'ui' is a valid member variable, that has accessible member pointer 'convertButton' that has an accessible member function 'hide()' - your code is correct.
With correct syntax your code will compile.
But correct systax is not enough for correct functionality.
Why your program does not function the way you expect it is another question, which has to do with your programs design.
But that is another story, which I suggest you leave at the moment.
Concentrate on C++ first.
Do some simple example programs and learn the concept.
Just readin one chapter in the book, does not make you REALLY know object oriented programming.

Salazaar
12th June 2007, 20:27
Do you really think that all I know about C++ is how to access class member?? I know C++ quite well, but I didn't use classes in my problem, that's the reason why I didn't understand "accessing GUI elements", and it doesn't mean that I don't know C++. What is wrong in my code? I really don't know... Regards

wysota
12th June 2007, 21:24
I know C++ quite well, but I didn't use classes in my problem,
If you didn't use classes, what did you use then? Is the code of any of your programs available for download? I'd like to take a look at it.

Salazaar
12th June 2007, 22:09
I used combination of functions. No, the code isn't availible because as I said once my console programs are histroy. I'll ask you once more, why my application doesn't have functionality? Regards

wysota
12th June 2007, 23:46
I used combination of functions.
So where was C++ in that? Maybe it was C then?


No, the code isn't availible because as I said once my console programs are histroy.
That's a pitty... Were they some school projects or something you did for fun?


I'll ask you once more, why my application doesn't have functionality?
Define "functionality". Does it contain widgets? Are they connected using signals and slots? Give us more details (be warned though, we'll still be assuming you know what you're doing regarding C++ syntax and semantics).

steg90
13th June 2007, 10:16
You are being very forceful and expecting the good people on here just to fix your problem.

You have been told to read more on C++ and I believe you should do. The best way to learn and fix your problems is by sitting down and trying to do it yourself first.

I'm sorry to sound hard, but having read lots of your posts, it seems you are just expecting to post your code on here and expect it to be fixed for you.

high_flyer
13th June 2007, 10:55
I'll ask you once more, why my application doesn't have functionality?
We don't even know what functionality you are talking about.
Do you know how to use signals and slots?

Salazaar
13th June 2007, 19:30
We don't even know what functionality you are talking about.
Objects on which I was doing:

ui.element->hide();
doesn't work, nextStepButton does nothing and so on. Maybe It'll b e better if you can see my code. I'll attach dialog.cpp


Do you know how to use signals and slots?
Your kidding me?;) Of course, I know.
edit:
The problem isn't that I don't know how to connect signals to slots, I have functions which do something, connected to something and all should work, but it doesn't. Look at my file

high_flyer
13th June 2007, 23:43
well, settingUp() is a bunch of if() clauses.
Probably none of them gets to be true, so nothing happens.
Put a debug statement in and see if its being printed:


bool Dialog::settingUp()
{
qDebug()<<"Dialog::settingUp()";
//the rest of your code.
}


In addition make sure you get no signal/slot warnings when you execute the application.

Salazaar
14th June 2007, 12:03
well, settingUp() is a bunch of if() clauses.
Probably none of them gets to be true, so nothing happens.

None?? If I, let's say' check checkbox in one group, and second in second grop and if nextStep Button is clicked one if() clause sure returns true and all instructions in if() should be done. But even if is a problem (which I think it isn't a problem) some widgets should be hidden, and we can type any value (even string) to lineEdit, although I have a validator.


In addition make sure you get no signal/slot warnings when you execute the application.
No, I don't have any signal/slots warning when executing application.

high_flyer
14th June 2007, 12:33
did you try the code I gave you in the last post?

Salazaar
14th June 2007, 12:38
Yes, I tried it, application compiled with no errors, and no errors at launching.

high_flyer
14th June 2007, 12:54
Amm... yes, I expected as much, but the point was to see if you ar getting the debug message...:rolleyes:

EDIT:
you should start the application from the console

Salazaar
14th June 2007, 13:42
Debug message? What do you mean? I tried to type make all instead of make, and reached message that it cannot find file somename.dll. And if it's not the answer you were expecting, how can I reach debugg message?

high_flyer
14th June 2007, 13:50
Am... look at the code I gave you.
there is a line:


qDebug()<<"Dialog::settingUp()";


This will print 'Dialog::settingUp()' in the console if you run the application in the console, and if the slot will get executed.
If the slot will not get executed, the message will not be printed.
This will tell you if the problem is IN the slot, or that the problem is that the slot is not being called.

Just start the program in the console, and see what ouput you get.

No need for 'make all' or any other thing.

wysota
14th June 2007, 14:26
He's using Windows, so adding CONFIG+=console and rerunning qmake is advised.

Salazaar
14th June 2007, 14:51
I added this, rebuild application, console window opened (and also normal windows application with GUI opened) but the console was clear. What does it mean?

high_flyer
14th June 2007, 15:10
it means the slot is not being called.
But at the moment I don't have the time to review you code again...
So check every thing that has to do with the signal/slot connection.

Salazaar
14th June 2007, 15:37
Ok, I'll review it to find what's wrong. But even if the slot is not called, some widgets should be hidden even if there's no connection. Connection look:

connect(ui.nextStepButton, SIGNAL(clicked()), this, SLOT(settingUp()));

Salazaar
15th June 2007, 13:28
So what's wrong?

wysota
15th June 2007, 13:41
You tell us :) Did you come up with anything while reviewing your code? Because as for now you're the only one who saw it...

high_flyer
15th June 2007, 14:02
post ALL your code.
The one file yo posted looks ok.

Salazaar
15th June 2007, 14:15
post ALL your code.

Sure. Unfortunately my files are too big to attach them, I'll post it in rar file
http://download.yousendit.com/049347421EAD445D

high_flyer
15th June 2007, 14:20
you should really read and try SIMPLE examples untill you get how the ui aproach works in Qt.


int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QApplication::setStyle ( new QPlastiqueStyle() );
QDialog *window = new QDialog;
//Ui::Dialog ui;
//ui.setupUi(window);
app.setMainWindow(window);
window->show();
return app.exec();
}

high_flyer
15th June 2007, 14:24
Do you know how to use signals and slots?
Your kidding me? Of course, I know.


I am starting to think you are kidding me...



class Dialog : public QDialog/*, public Ui::Dialog*/ //what was that for??
{
Q_OBJECT

public:
Dialog(QWidget *parent = 0);


public slots: //<<----this is needed
bool settingUp();
void previousStep();

private:

Ui::Dialog ui;
};

Salazaar
15th June 2007, 14:34
I think public Ui::Dialog is needed to access gui elements

high_flyer
15th June 2007, 14:38
as I said, READ about it more.
You have a private ui elements which you use in your Dialog class.
If you use that approach you don't need to sublcass, one of the nice things about Qt4 ui way.

Salazaar
15th June 2007, 14:40
Right. But there is an error in line

app.setMainWindow(window);
class QApplication has no member named setMainWindow

high_flyer
15th June 2007, 14:46
that is correct.
What do you do then?

Salazaar
15th June 2007, 14:47
I don't know

high_flyer
15th June 2007, 14:49
Read the docs maybe??

wysota
15th June 2007, 15:15
Salazaar, are you using Qt Assistant? It has nice indexing and searching functions...

high_flyer
15th June 2007, 15:19
Oh allrgiht...
Salazar - I had a typo when in the code, and thought it might be a good lesson for you...
It should be QApplication::setMainWidget ()

wysota
15th June 2007, 15:23
Actually you shouldn't need that line at all.

high_flyer
15th June 2007, 15:28
True.
But it doesn't hurt. :)

Salazaar
15th June 2007, 16:16
Yes, I'm using assistant. I would check it in docs, but I just written that I don't know what's the problem about

Salazaar
15th June 2007, 16:32
I made this changes you post, but when i launch application, only dialog window appear. I mean, no gui elements are displayed, only empty window. is that a 'typo'?

high_flyer
15th June 2007, 17:07
I mean, no gui elements are displayed, only empty window. is that a 'typo'?
Yes, but this time its yours:


int main(int argc, char *argv[])

{
QApplication app(argc, argv);
QApplication::setStyle ( new QPlastiqueStyle() );
//QDialog *window = new QDialog;
Dialog *window = new Dialog;
window->show();
return app.exec();
}

wysota
15th June 2007, 17:28
Salazaar, please read and at least try to understand the code you write. I think you should be able to distinguish between "QDialog" and "Dialog".

Salazaar
15th June 2007, 19:16
It should be new Dialog. Right?

ad5xj
21st June 2007, 23:48
Debugging an application that crashes on startup is more difficult with designer ui modules than when you make the forms yourself. The designer generates a lot of MOC able code that gets compiled.

When you are just starting to learn Qt (or C++ for that matter) you may be better off learning how to manually construct the form first (using the examples and tutorials in Qt). Make the smallest runnable code changes that compile clean. For instance, just make a form that has a group box or frame on it. When you get that small amount of code to work, then add other controls to the working code one at a time.

In this way you narrow the search for the bugs to just the code you added. It is much easier to debug a few lines of code than several hundred generated by the designer. Especially when you don't understand what it all does.

Hope this helps.

jacek
22nd June 2007, 01:11
It is much easier to debug a few lines of code than several hundred generated by the designer.
Sure, but one can safely assume that the code generated by the Designer is OK (which in fact means that you have less code to debug, if you use Designer). Although one shouldn't use a code generator, if he doesn't understand the generated code, so you are right, that it's better to start with learning how to create GUI in code.