Hi, because im new in Qt i use old method from std to create log, i try project with logging
But always big problem.
After i init log (create and write main infos)
When i next use example “QLog() << “Test123”;” It shut down app
My current code:
- void Log::Init()
- // Launcher Dir
- QDir dir;
- // Create Log & Init
- const QString LogPath = setting_class->Launcher_Dir + "//" + setting_class->Launcher_LogName;
- std::ofstream LogStream;
- LogStream.open(LogPath.toStdString(), std::ios_base::out | std::ios_base::trunc);
- QLog << "Test test" << std::endl; // THIS WORKING WRITE SUCCESS
- include "Log.h"
- int main(int argc, char* argv)
- Log log;
- QLog << "TEst 3333" << std::endl; // SHUT APP :/
Other code i remove for better preview.. ofc i have MainWindow.
Where can be mistake?
I would propose to use plain ofstream. You try to make it fancy with reassigning rdbuf. I guess this makes it too complicated for yourself. As already explained in the post above. You are creating an ofstream “LogStream” and it is killed as soon as leave the Init routine.
Line 2 and 3 of your header: What is this for? Dangling something without relation to the rest. I do not see a relation to your Log class.
May be you should have a look to QDebug [qt-project.org]
Apart from redesign issues:
your code exits on line 7 (8 actually) because that is where your main() ends – so it should not surprise you. In Qt, we usually use QApplication [qt-project.org] or QCoreApplication [qt-project.org], esp. their exec() methods. Take a look at some examples to get to know how to use them, or look how Qt Creator auto-generates code there.