Re: Program crashes (SIGSEGV)
Code:
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:
Code:
QString version
= "0.0.1 pre-alpha";
I suggest using:
Code:
#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 ).
Re: Program crashes (SIGSEGV)
@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:
Code:
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:
Code:
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?
Re: Program crashes (SIGSEGV)
Quote:
Originally Posted by
Voldemort
@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:
Code:
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.
Re: Program crashes (SIGSEGV)
Quote:
Originally Posted by
wysota
From what I understand you have a declaration like the following somewhere:
Code:
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?
Re: Program crashes (SIGSEGV)
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
Re: Program crashes (SIGSEGV)
I second what Marcel says. I'd even suggest subclassing QApplication and putting your object as a member of the application.
Code:
public:
m_x = new X(this);
}
X *x() const { return m_x; }
private:
X *m_x;
};
A redefinition of qApp might also come in handy:
Code:
#ifdef qApp
#undef qApp
#endif
#define qApp static_cast<MyApp*>(QCoreApplication::instance())
Re: Program crashes (SIGSEGV)
Quote:
Originally Posted by
wysota
I second what Marcel says. I'd even suggest subclassing QApplication and putting your object as a member of the application.
Code:
public:
m_x = new X(this);
}
X *x() const { return m_x; }
private:
X *m_x;
};
A redefinition of qApp might also come in handy:
Code:
#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
Re: Program crashes (SIGSEGV)
I understand what you mean. But I have questions:
Code:
#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?
Re: Program crashes (SIGSEGV)
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
Re: Program crashes (SIGSEGV)
Quote:
Originally Posted by
marcel
1. In the source file in which you will implement your subclass of QApplication.
Header file, to be exact.
1 Attachment(s)
Re: Program crashes (SIGSEGV)
I've tried to make such a class (source is in the attachment), but I get these errors:
Quote:
/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?
Re: Program crashes (SIGSEGV)
In header file this:
should be like this:
Code:
QQMsnApplication(int a, char **b);
Re: Program crashes (SIGSEGV)
That solves some errors, but these are still present:
Quote:
/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?
Re: Program crashes (SIGSEGV)
"‘arg’ was not declared in this scope" - should probably be "argc" or "argv".
Re: Program crashes (SIGSEGV)
You have to use the members from QMSNApplication, namely:
Code:
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
Re: Program crashes (SIGSEGV)
Actually, I looked better now.
You already have accessors. Then why not use them?
I am talking about:
Code:
public:
~QQMsnApplication();
debugger *debug();
cmsn *msn();
Window_Login *window_login();
Window_Login_Busy *login_busy();
Use them in main.
Code:
QQMsnApp.window_login()->show_start();
QQMsnApp.window_login()->show();
Re: Program crashes (SIGSEGV)
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:
Code:
window_login()->show_start();
with the current code. Or will I always have to put QQMsnApp. before it?
3)
Code:
#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?
Re: Program crashes (SIGSEGV)
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
Re: Program crashes (SIGSEGV)
It doesn't work, I put this at the top of the header file:
Code:
#ifdef qApp
#undef qApp
#endif
#define qApp static_cast<QQMsnApp>(QCoreApplication::instance())
And in the function StartLogin() I use this:
Code:
//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:
Quote:
/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?
Re: Program crashes (SIGSEGV)
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.