Solved how to use the elements that is not belong in your class
-
@dheerendra
I want to using the specific String that i will give it in the MainWindow and used it in my CandumThread class.Is this will cause any problem?
-
@dheerendra
Do you have any suggestion to do it better?
cause i don't want cannum to be the static String cause i will need to change the value in the MainWindow if i need. -
When are u assigning this string value ? Just check how static variable work in c++. It should help.
-
@dheerendra
I will assigned it in the MainWindow.
And i will want to used it at CandumpThread.i change ti into static const and still not work.
-
@victor-wang If MainWindow is using CandumpThread then just pass that string from MainWindow to CandumpThread constructor.
Don't make cannum static! Your CandumpThread class should not know anything about MainWindow (it would be bad design if it would know). -
@victor-wang I moved this thread to "C++ gurus" forum as your question is not related to Qt but to C++.
-
@jsulm
Thx a lot!
I have solve the problem.
I add this program.DIDOThread::DIDOThread(QObject *parent) : QThread(parent) { p = (MainWindow *)parent; }
It work for me in my DIDOThread class!
-
@victor-wang Bad design...
You should instead pass the string as parameter:DIDOThread::DIDOThread(const QString &cannum, QObject *parent) : QThread(parent) { }
And if you still want to do it like you shown then you should at least use C++ style cast not C.
-
@jsulm
You mean i can add this program in my DIDOThread.h file? -
@victor-wang Yes, you just add "const QString &cannum" to your constructor in DIDOThread as I shown.