PDA

View Full Version : Program crashes (SIGSEGV)



Voldemort
9th May 2007, 21:08
Hello,

My program crashes sometimes (SIGSEGV - Segmentation fault). This is (a part of) the code:

This shows the error message when the connection with the server was broken or stopped.

void Window_Login_Busy::show_errors(int sort_error)
{
close();
window_login->show();
progressbar->setValue(0);

QString text = "Aanmelden mislukt";
if(sort_error == 1)
text += ": Disconnected from server.";
else if (sort_error == 2)
text += ": Gebruikersnaam of wachtwoord is fout.";

QMessageBox err;
err.setIcon(QMessageBox::Warning);
err.setWindowTitle("QQMsn: Error");
err.setText(text);
err.exec();

//debug->setData("bla");
}and

Here someone entered the wrong password, I break the connection with the server.

while(ssl_sck_dalogin->canReadLine())
{
[...]
else if(line.contains("HTTP/1.1 302 FOUND"))
{
debug->setData("Redirect");

break;
}
[...]
}and

This is the emited slot when I close the connection, it uses the standard Qt signal:

connect(socket, SIGNAL(disconnected()), SLOT(isDisconnected()));

login_busy->show_errors(1); is the function in the first code I posted.


void cmsn::isDisconnected()
{
debug->setData("\nDisconnected from host (Notification server).");

if(login_busy->change_lbl)
login_busy->show_errors(1);
}When someone enters the wrong password, I get an error dialog with an Ok button, the login screen is showed and the login_busy is closed. But when you close that screen or press the Ok button, the program receives the SIGSEGV signal and crashes.

gdb says:


`/home/quinten/QQMsn_build/QQMsn' has changed; re-reading symbols.
Starting program: /home/quinten/QQMsn_build/QQMsn
Failed to read a valid object file image from memory.
[Thread debugging using libthread_db enabled]
[New Thread -1223088432 (LWP 4881)]
[New Thread -1225602160 (LWP 4882)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1223088432 (LWP 4881)]When I don't show an MessageBox, the program does not crash and gdb says:


Starting program: /home/quinten/QQMsn_build/QQMsn
Failed to read a valid object file image from memory.
[Thread debugging using libthread_db enabled]
[New Thread -1222646064 (LWP 4927)]
[New Thread -1225159792 (LWP 4928)]
[Thread -1225159792 (LWP 4928) exited]

Program exited normally.
There are some cases where the server closes the connection (e.g. entering a wrong username). In that case, the same slot is emited, the
MessageBox shows, and when pressing OK, the MessageBox closes and the program doesn't crash.


Why does my program crash? How can I solve it? I don't understand where the error is, in my ssl class, in my window_login class, in Qt, in OpenSSL or somewhere else? When you need the whole source code, I'll post it.

marcel
9th May 2007, 21:27
My assumption is that calling close() in show_errors causes a lot of problems.
It will post a close event in the event loop. But then you show a modal warning message box. This will block all activity in your window, and show_errors will not exit until you close the dialog.

Try using hide() instead if you can, or show the warning message box and the login window after the main window is closed. You could do something about this in close event.

Or, in isDisconnected, call showErrors and then call login_busy->close() right after it, but remove close() from show_errors().

Perhaps it would be more helpful if you posted the entire code, so somebody can testy it.

Regards

jacek
9th May 2007, 21:36
Could we see the backtrace? Do you use threads in your application?

Voldemort
12th May 2007, 11:56
When I remove the close(); (just for testing), it still crashes, so I think the problem is not the close(); but something else.

Where can I find backtraces?

What are threads?

Source
The source is in the attachment.

Licence
GPLv2

Info
When you enter your MSN and correct password, it will stay to 100%, that's because I have to program the other things. The crash happens only when you enter a valid mailadres and a wrong password.

Requirements
Qt 4.3
CMake (don't know which version, I use CMake 2.4.6)

Compiling

mkdir QQMsn_build
cd QQMsn_build
cmake ../<source_dir>
make

wysota
12th May 2007, 13:04
Where can I find backtraces?
Enter "bt" in gdb after the application crashes.


What are threads?
http://en.wikipedia.org/wiki/Thread_(computer_science)

Voldemort
12th May 2007, 15:32
Backtrace:


#0 0xb668ad83 in SSL_read () from /usr/lib/libssl.so
#1 0x00000004 in ?? ()
#2 0x00000004 in ?? ()
#3 0x00000000 in ?? ()

But I don't understand a backtrace, how do you have to read it? Where can you find the crucial information in the backtrace?

I don't think I use threads.

wysota
12th May 2007, 16:12
First you have to compile your application with debug information (CONFIG+=debug in .pro file). Adding QMAKE_CXXFLAGS+=-ggdb will give you even more info.

Voldemort
12th May 2007, 16:35
But I use CMake, not QMake, how can I do the same in CMake?

wysota
12th May 2007, 17:18
Consult the manual on how to set CXXFLAGS for your project.

Voldemort
12th May 2007, 17:56
I can't find the answer in the documentation

http://www.cmake.org/HTML/Documentation.html

wysota
12th May 2007, 18:21
set(CMAKE_CXX_FLAGS "-ggdb")

Voldemort
13th May 2007, 10:28
I added the line, but there is no difference, I think I have to this:


First you have to compile your application with debug information (CONFIG+=debug in .pro file).

But how do I have to set this option?

marcel
13th May 2007, 11:37
In the .pro file you have to add that line.

wysota
13th May 2007, 15:46
@marcel: He doesn't use qmake.

It's enough if you add the -ggdb flag.

Voldemort
13th May 2007, 20:11
There changes nothing:


# gdb ./QQMsn 2> ../QQMsn_debug.txt
GNU gdb 6.5
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i586-suse-linux"...Using host libthread_db library "/lib/libthread_db.so.1".

(gdb) run
Starting program: /home/quinten/QQMsn_build/QQMsn
[Thread debugging using libthread_db enabled]
[New Thread -1222338864 (LWP 4290)]
[New Thread -1224852592 (LWP 4297)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1222338864 (LWP 4290)]
0xb66f7d83 in SSL_read () from /usr/lib/libssl.so
(gdb) bt
#0 0xb66f7d83 in SSL_read () from /usr/lib/libssl.so
#1 0x00000004 in ?? ()
#2 0x00000004 in ?? ()
#3 0x00000000 in ?? ()
(gdb) kill
Kill the program being debugged? (y or n) y


But I don't understand a backtrace, how do you have to read it? Where can you find the crucial information in the backtrace?

marcel
13th May 2007, 20:40
From what I see in the call stack, it crashes in libssl.
Qt supports SSL from 4.3. Did you link with the correct( required ) ssl library ?
Maybe you didn't have the correct version when you compiled Qt. Anyway, It does not make a lot of sense crashing at that point ( perhaps a bug in Qt related to SSL ? ).

Try disabling SSL from QHttp, if you can...

To Wysota: It doesn't matter if he enables debugging information in his app, because it crashes in another lib.

Regards

wysota
13th May 2007, 21:09
To Wysota: It doesn't matter if he enables debugging information in his app, because it crashes in another lib.

Of course it matters - something calls this "another lib", right?. As you can see three symbols are not identified correctly. And it looks like a corrupted stack (look at symbol addresses, it looks like the frame stack is incorrect), by the way, so I suggest doing "make distclean && qmake && make" first to make sure the app is compiled properly. Blaiming OpenSSL is certainly not the way to go.

jacek
13th May 2007, 21:29
#3 0x00000000 in ?? ()
It looks like you try to dereference a null pointer somewhere. Make sure you create all Qt objects after QApplication instance was created.


But I use CMake, not QMake, how can I do the same in CMake?
Run ccmake and set CMAKE_BUILD_TYPE to Debug.

Voldemort
14th May 2007, 18:15
1) I create QOBjects before I use QApplication, but that's because otherwise extern won't work (main.cpp). Is that the cause of the crash? How can I solve this problem?

2) How do I disable SSL from QHttp? I need a QSslSocket, so disabling SSL will cause my application won't work.

3) CMAKE_BUILD_TYPE is set to "Debug", no change in the bactrace?

wysota
14th May 2007, 18:30
Why not use a pointer to QObject?

marcel
14th May 2007, 19:03
QString version = "0.0.1 pre-alpha";

debugger *debug = new debugger("QQMsn_debug",version,true);
cmsn *msn = new cmsn();
Window_Login *window_login = 0;
Window_Login_Busy *login_busy = 0;


Why do you create those objects like that? I believe there is something drawing you back to C :).

Instead of:


QString version = "0.0.1 pre-alpha";

I suggest using:


#define VERSION "0.0.1 pre-alpha"


Regarding the other static objects - you delete them in main :).
A really "static desing" would have supposed to implement something like AllocateObject ( called before main ) and ReleaseObject( called after main ).

So, I suggest dragging the statics in main, after the QApplication is created, because I don't see any reason why you should keep them there.

As for the segfault, as jacek said you most likely have a QSslSocket in an unallocated QMsn object ( from what I have seen in your code ).

Voldemort
15th May 2007, 20:07
@wysota:

1) What do you mean? I include and inheritance QObject in the classes... Can you explain (with an example?)?

@marcel:

2) How can I read the version? When I do this:


setData("File generated by QQMsn " + VERSION);

(debugger.cpp)

It doesn't work (VERSION not declared). How can I read it? Can you give a little example?

3) Which thing do I still have to delete in main? Do you mean this:


debugger *debug = new debugger("QQMsn_debug",true);
cmsn *msn = new cmsn();
Window_Login *window_login = 0;
Window_Login_Busy *login_busy = 0;

?

But when I put these in main, I can't use extern in other files... Can you give an example?

wysota
15th May 2007, 23:16
@wysota:

1) What do you mean? I include and inheritance QObject in the classes... Can you explain (with an example?)?


From what I understand you have a declaration like the following somewhere:


extern SomeClass obj;

where SomeClass inherits QObject. So I suggest to use a pointer to the object instead of the object itself, so that you can create the object and assign it to the pointer after the application object is created.

Voldemort
16th May 2007, 13:51
From what I understand you have a declaration like the following somewhere:


extern SomeClass obj;where SomeClass inherits QObject. So I suggest to use a pointer to the object instead of the object itself, so that you can create the object and assign it to the pointer after the application object is created.

I understand a bit what you meaning, but not everything. Can you give an example?

marcel
16th May 2007, 13:56
Have you thought about applying the singleton pattern?
This means that your static objects will have something like a static GetInstance method that will return a pointer to the single instance (static,also ).

There will be no need to use "extern", just call GetInstance wherever you need it ( but make sure to include the necessary files ).

Regards

wysota
16th May 2007, 14:35
I second what Marcel says. I'd even suggest subclassing QApplication and putting your object as a member of the application.


class MyApp : public QApplication{
public:
MyApp(int a, char **b) : QApplication(a,b){
m_x = new X(this);
}
X *x() const { return m_x; }
private:
X *m_x;
};

A redefinition of qApp might also come in handy:

#ifdef qApp
#undef qApp
#endif
#define qApp static_cast<MyApp*>(QCoreApplication::instance())

marcel
16th May 2007, 14:38
I second what Marcel says. I'd even suggest subclassing QApplication and putting your object as a member of the application.


class MyApp : public QApplication{
public:
MyApp(int a, char **b) : QApplication(a,b){
m_x = new X(this);
}
X *x() const { return m_x; }
private:
X *m_x;
};A redefinition of qApp might also come in handy:

#ifdef qApp
#undef qApp
#endif
#define qApp static_cast<MyApp*>(QCoreApplication::instance())

Yes. Now he won't even need to include additional files because there will be qApp.

Regards

Voldemort
16th May 2007, 21:57
I understand what you mean. But I have questions:


#ifdef qApp
#undef qApp
#endif
#define qApp static_cast<MyApp*>(QCoreApplication::instance())1) Where do I have to put this part? Every file? Just in the class file? Somewhere else?

2) With that code I have to include some classes I use (the part above my main function in main.cpp)?

3) Do I have to instantiate the class in all files or just in the main function? Or does it work in another way?

4) Can I put the delete lines (now at the bottom of my main function in main.cpp) in the destructor of the class?

marcel
16th May 2007, 22:21
1. In the source file in which you will implement your subclass of QApplication.
2. Only your QApplication class.
3. Just the main function.
4. Yes, if they will be the members of your custom QApplication, then you can put them in its destructor.

Regards

wysota
16th May 2007, 22:35
1. In the source file in which you will implement your subclass of QApplication.

Header file, to be exact.

Voldemort
17th May 2007, 10:05
I've tried to make such a class (source is in the attachment), but I get these errors:


/home/quinten/QQMsn_test/src/QQMsnApplication.h: In constructor ‘QQMsnApplication::QQMsnApplication(int, char**)’:
/home/quinten/QQMsn_test/src/QQMsnApplication.h:31: error: expected `{' at end of input
/home/quinten/QQMsn_test/src/main.cpp: In function ‘int main(int, char**)’:
/home/quinten/QQMsn_test/src/main.cpp:35: error: ‘arg’ was not declared in this scope
/home/quinten/QQMsn_test/src/main.cpp:37: error: invalid use of member (did you forget the ‘&’ ?)
/home/quinten/QQMsn_test/src/main.cpp:37: error: base operand of ‘->’ is not a pointer
/home/quinten/QQMsn_test/src/main.cpp:38: error: invalid use of member (did you forget the ‘&’ ?)
/home/quinten/QQMsn_test/src/main.cpp:38: error: base operand of ‘->’ is not a pointer
make[2]: *** [CMakeFiles/QQMsn.dir/src/main.o] Fout 1
make[1]: *** [CMakeFiles/QQMsn.dir/all] Fout 2
make: *** [all] Fout 2

Why? What do I wrong?

wysota
17th May 2007, 10:22
In header file this:

QQMsnApplication(int a, char **b) : QApplication(a,b);
should be like this:

QQMsnApplication(int a, char **b);

Voldemort
17th May 2007, 21:59
That solves some errors, but these are still present:


/home/quinten/QQMsn_test/src/main.cpp: In function ‘int main(int, char**)’:
/home/quinten/QQMsn_test/src/main.cpp:35: error: ‘arg’ was not declared in this scope
/home/quinten/QQMsn_test/src/main.cpp:37: error: ‘window_login’ was not declared in this scope
make[2]: *** [CMakeFiles/QQMsn.dir/src/main.o] Fout 1
make[1]: *** [CMakeFiles/QQMsn.dir/all] Fout 2
make: *** [all] Fout 2

What is the bug?

wysota
17th May 2007, 22:02
"‘arg’ was not declared in this scope" - should probably be "argc" or "argv".

marcel
17th May 2007, 22:03
You have to use the members from QMSNApplication, namely:


m_window_login = new Window_Login();
m_login_busy = new Window_Login_Busy();

I didn't look too much at the code, but if you don't have accessors for them, then create them.

As for the "arg" error, make sure that the parameter names of main coincide with the parameters of your qmsnapplication - argc and argv.

Regards

marcel
17th May 2007, 22:14
Actually, I looked better now.

You already have accessors. Then why not use them?
I am talking about:


public:
QQMsnApplication(int a, char **b) : QApplication(a,b);
~QQMsnApplication();
debugger *debug();
cmsn *msn();
Window_Login *window_login();
Window_Login_Busy *login_busy();


Use them in main.


QQMsnApp.window_login()->show_start();
QQMsnApp.window_login()->show();

Voldemort
18th May 2007, 09:55
1) I've changed that, but now I have errors in other classes (in window_login.cpp & window_login.h), they complain ‘QQMsnApp’ was not declared. How do I resolve this?

2) Isn't there an option that I simply can do this:


window_login()->show_start();with the current code. Or will I always have to put QQMsnApp. before it?

3)
#ifdef qApp
#undef qApp
#endif
#define qApp static_cast<MyApp*>(QCoreApplication::instance())

What do I have to do with these lines? Why should I add them?

marcel
18th May 2007, 10:01
2) No, since now they are objects of QMSNApp. I don't see any problem with this.

3. You need that for 1) and 2).
Wherever you need QMsnApp use qApp instead and access QMsn and the other memebers with the functions you created.

Regards

Voldemort
18th May 2007, 11:25
It doesn't work, I put this at the top of the header file:


#ifdef qApp
#undef qApp
#endif
#define qApp static_cast<QQMsnApp>(QCoreApplication::instance())

And in the function StartLogin() I use this:


//Variablen goed zetten
qApp.cmsn()->setMail(mail->text());
qApp.cmsn()->setPass(pass->text());

//Toon het nieuwe venster (login_busy)
if(!started_login_busy)
{
qApp.login_busy()->show_start();
started_login_busy = true;
}

qApp.login_busy()->show();

//De functie aanroepen die de socket opent en het eerst commando zend
qApp.cmsn()->StartLogin();

But it doesn't work, I get this:


/home/quinten/QQMsn_test/src/window_login.cpp: In member function ‘void Window_Login::startLogin()’:
/home/quinten/QQMsn_test/src/window_login.cpp:82: error: expected type-specifier before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:82: error: expected `>' before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:82: error: expected `(' before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:82: error: ‘QQMsnApp’ was not declared in this scope
/home/quinten/QQMsn_test/src/window_login.cpp:82: error: ‘QCoreApplication’ has not been declared
/home/quinten/QQMsn_test/src/window_login.cpp:82: error: expected `)' before ‘;’ token
/home/quinten/QQMsn_test/src/window_login.cpp:83: error: expected type-specifier before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:83: error: expected `>' before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:83: error: expected `(' before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:83: error: ‘QCoreApplication’ has not been declared
/home/quinten/QQMsn_test/src/window_login.cpp:83: error: expected `)' before ‘;’ token
/home/quinten/QQMsn_test/src/window_login.cpp:88: error: expected type-specifier before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:88: error: expected `>' before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:88: error: expected `(' before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:88: error: ‘QCoreApplication’ has not been declared
/home/quinten/QQMsn_test/src/window_login.cpp:88: error: expected `)' before ‘;’ token
/home/quinten/QQMsn_test/src/window_login.cpp:92: error: expected type-specifier before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:92: error: expected `>' before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:92: error: expected `(' before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:92: error: ‘QCoreApplication’ has not been declared
/home/quinten/QQMsn_test/src/window_login.cpp:92: error: expected `)' before ‘;’ token
/home/quinten/QQMsn_test/src/window_login.cpp:95: error: expected type-specifier before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:95: error: expected `>' before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:95: error: expected `(' before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:95: error: ‘QCoreApplication’ has not been declared
/home/quinten/QQMsn_test/src/window_login.cpp:95: error: expected `)' before ‘;’ token
make[2]: *** [CMakeFiles/QQMsn.dir/src/window_login.o] Fout 1
make[1]: *** [CMakeFiles/QQMsn.dir/all] Fout 2
make: *** [all] Fout 2

What is now wrong?

wysota
18th May 2007, 11:33
Compare my define and yours. They differ by a one very important character. Also make sure header files defining classes you reference are always included.

Voldemort
18th May 2007, 15:15
I've changed that, but I have changed the QQMsnApplication class (there were errors):


debugger* QQMsnApplication::debug()
{
return m_debug;
}

cmsn* QQMsnApplication::msn()
{
return m_msn;
}

Window_Login* QQMsnApplication::window_login()
{
return m_window_login;
}

Window_Login_Busy* QQMsnApplication::login_busy()
{
return m_login_busy;
}But as I said, I still get errors, these are:


/home/quinten/QQMsn_test/src/window_login.cpp: In member function ‘void Window_Login::startLogin()’:
/home/quinten/QQMsn_test/src/window_login.cpp:82: error: expected type-specifier before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:82: error: expected `>' before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:82: error: expected `(' before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:82: error: ‘QQMsnApp’ was not declared in this scope
/home/quinten/QQMsn_test/src/window_login.cpp:82: error: expected primary-expression before ‘>’ token
/home/quinten/QQMsn_test/src/window_login.cpp:82: error: ‘QCoreApplication’ has not been declared
/home/quinten/QQMsn_test/src/window_login.cpp:82: error: expected `)' before ‘;’ token
/home/quinten/QQMsn_test/src/window_login.cpp:83: error: expected type-specifier before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:83: error: expected `>' before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:83: error: expected `(' before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:83: error: expected primary-expression before ‘>’ token
/home/quinten/QQMsn_test/src/window_login.cpp:83: error: ‘QCoreApplication’ has not been declared
/home/quinten/QQMsn_test/src/window_login.cpp:83: error: expected `)' before ‘;’ token
/home/quinten/QQMsn_test/src/window_login.cpp:88: error: expected type-specifier before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:88: error: expected `>' before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:88: error: expected `(' before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:88: error: expected primary-expression before ‘>’ token
/home/quinten/QQMsn_test/src/window_login.cpp:88: error: ‘QCoreApplication’ has not been declared
/home/quinten/QQMsn_test/src/window_login.cpp:88: error: expected `)' before ‘;’ token
/home/quinten/QQMsn_test/src/window_login.cpp:92: error: expected type-specifier before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:92: error: expected `>' before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:92: error: expected `(' before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:92: error: expected primary-expression before ‘>’ token
/home/quinten/QQMsn_test/src/window_login.cpp:92: error: ‘QCoreApplication’ has not been declared
/home/quinten/QQMsn_test/src/window_login.cpp:92: error: expected `)' before ‘;’ token
/home/quinten/QQMsn_test/src/window_login.cpp:95: error: expected type-specifier before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:95: error: expected `>' before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:95: error: expected `(' before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:95: error: expected primary-expression before ‘>’ token
/home/quinten/QQMsn_test/src/window_login.cpp:95: error: ‘QCoreApplication’ has not been declared
/home/quinten/QQMsn_test/src/window_login.cpp:95: error: expected `)' before ‘;’ token
make[2]: *** [CMakeFiles/QQMsn.dir/src/window_login.o] Fout 1
make[1]: *** [CMakeFiles/QQMsn.dir/all] Fout 2
make: *** [all] Fout 2What is wrong?

jacek
18th May 2007, 15:21
What is wrong?
You are missing #include directives.

wysota
18th May 2007, 15:24
Do you have a QQMsnApp class at all? Because I see you have QQMsnApplication. Please read and try to understand the errors the compiler tells you. These are pretty straightforward to understand.

Voldemort
19th May 2007, 09:17
You are missing #include directives.

I added


#include <QCoreApplication>

before the define, undef, ...

No difference in errors.


Do you have a QQMsnApp class at all? Because I see you have QQMsnApplication. Please read and try to understand the errors the compiler tells you. These are pretty straightforward to understand.

The class its name is QQMsnApplication, but in main.cpp, I do this in main.cpp:


QQMsnApplication QQMsnApp(argc,argv);

Thats why I use QQMsnApp. Or am I wrong?

wysota
19th May 2007, 09:47
Yes, you are wrong. You should use QQMsnApplication in the definition. You put the class in the sharp brackets (<>) to indicate the template class and QCoreApplication::instance() is used to fetch the actual instance of the application. Just copy my definition exactly only changing MyApp* to QQMsnApplication*.

marcel
19th May 2007, 09:53
/home/quinten/QQMsn_test/src/window_login.cpp: In member function ‘void Window_Login::startLogin()’:
/home/quinten/QQMsn_test/src/window_login.cpp:82: error: expected type-specifier before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:82: error: expected `>' before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:82: error: expected `(' before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:82: error: ‘QQMsnApp’ was not declared in this scope
/home/quinten/QQMsn_test/src/window_login.cpp:82: error: ‘QCoreApplication’ has not been declared
/home/quinten/QQMsn_test/src/window_login.cpp:82: error: expected `)' before ‘;’ token
/home/quinten/QQMsn_test/src/window_login.cpp:83: error: expected type-specifier before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:83: error: expected `>' before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:83: error: expected `(' before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:83: error: ‘QCoreApplication’ has not been declared
/home/quinten/QQMsn_test/src/window_login.cpp:83: error: expected `)' before ‘;’ token
/home/quinten/QQMsn_test/src/window_login.cpp:88: error: expected type-specifier before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:88: error: expected `>' before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:88: error: expected `(' before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:88: error: ‘QCoreApplication’ has not been declared
/home/quinten/QQMsn_test/src/window_login.cpp:88: error: expected `)' before ‘;’ token
/home/quinten/QQMsn_test/src/window_login.cpp:92: error: expected type-specifier before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:92: error: expected `>' before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:92: error: expected `(' before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:92: error: ‘QCoreApplication’ has not been declared
/home/quinten/QQMsn_test/src/window_login.cpp:92: error: expected `)' before ‘;’ token
/home/quinten/QQMsn_test/src/window_login.cpp:95: error: expected type-specifier before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:95: error: expected `>' before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:95: error: expected `(' before ‘QQMsnApp’
/home/quinten/QQMsn_test/src/window_login.cpp:95: error: ‘QCoreApplication’ has not been declared
/home/quinten/QQMsn_test/src/window_login.cpp:95: error: expected `)' before ‘;’ token
make[2]: *** [CMakeFiles/QQMsn.dir/src/window_login.o] Fout 1
make[1]: *** [CMakeFiles/QQMsn.dir/all] Fout 2
make: *** [all] Fout 2
You must not use QMsnApp.
You redefined qApp but you also have to use it.
qApp is a global pointer to your application's instance ( custom app in this case ).
This means that you can do things like qApp->windowlogin()->show(), etc.

So: make sure you redefined qApp correctly, as wysota pointed. Make sure that in other files, when you want to access QMsnApp, use instead qApp. Again, this is the reason you redefined it in the first place.

And please read this link: qApp (http://doc.trolltech.com/latest/qapp.html).( or look for it in assistant )
This is basic c++ you are asking here. There isn't much related to Qt ( a global pointer is not really Qt-dependent ).

As it is said in other, resemblant posts, telling you how to make it work won't help you understand. Next time you will get these errors again and you won't know what to do.

So, at least try to understand the explanations that are given to you here, and make connections between them.

Regards.

Voldemort
21st May 2007, 18:13
I changed it, but still no difference, the same errors.

definition in header file

#ifdef qApp
#undef qApp
#endif
#define qApp static_cast<QQMsnApplication*>(QCoreApplication::instance())


use in source file

//Variablen goed zetten
qApp->cmsn()->setMail(mail->text());
qApp->cmsn()->setPass(pass->text());

//Toon het nieuwe venster (login_busy)
if(!started_login_busy)
{
qApp->login_busy()->show_start();
started_login_busy = true;
}

qApp->login_busy()->show();

//De functie aanroepen die de socket opent en het eerst commando zend
qApp->cmsn()->StartLogin();


main in main.cpp


int main(int argc, char *argv[])
{
QQMsnApplication QQMsnApplication(argc,argv);

QQMsnApplication.window_login()->show_start();
QQMsnApplication.window_login()->show();

//qDebug() << "Test";

return QQMsnApplication.exec();
}

What goes wrong?


I know I ask basic C++ questions, but I try to learn C++ with Qt. I don't like programming with Konsole windows, I more like to use real windows.

wysota
21st May 2007, 21:09
The code is the same regardless where you program. What is stopping you from using graphical editors?

About your question - don't call the variable the same as the class is called.

Change:

QQMsnApplication QQMsnApplication(argc,argv);
to

QQMsnApplication app(argc,argv);

Of course all other occurences have to be modified as well.