Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qgroundcontrol
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
a552bc72
Commit
a552bc72
authored
Apr 06, 2016
by
Nate Weibley
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix force close issues on android by enforcing queued connections on the QStringListModel
parent
3c0c2607
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
17 deletions
+41
-17
AppMessages.cc
src/QmlControls/AppMessages.cc
+30
-13
AppMessages.h
src/QmlControls/AppMessages.h
+11
-4
No files found.
src/QmlControls/AppMessages.cc
View file @
a552bc72
...
...
@@ -21,15 +21,18 @@ This file is part of the QGROUNDCONTROL project
======================================================================*/
// Allows QGlobalStatic to work on this translation unit
#define _LOG_CTOR_ACCESS_ public
#include "AppMessages.h"
#include <QFile>
#include <QStringListModel>
#include <QtConcurrent>
#include <QTextStream>
AppLogModel
AppLogModel
::
instance
;
Q_GLOBAL_STATIC
(
AppLogModel
,
debug_model
)
static
QtMessageHandler
old_handler
;
static
AppLogModel
&
debug_strings
=
AppLogModel
::
getModel
();
static
void
msgHandler
(
QtMsgType
type
,
const
QMessageLogContext
&
context
,
const
QString
&
msg
)
{
...
...
@@ -38,9 +41,7 @@ static void msgHandler(QtMsgType type, const QMessageLogContext &context, const
// Avoid recursion
if
(
!
QString
(
context
.
category
).
startsWith
(
"qt.quick"
))
{
const
int
line
=
debug_strings
.
rowCount
();
debug_strings
.
insertRows
(
line
,
1
);
debug_strings
.
setData
(
debug_strings
.
index
(
line
),
output
,
Qt
::
DisplayRole
);
debug_model
->
log
(
output
);
}
if
(
old_handler
!=
nullptr
)
{
...
...
@@ -52,20 +53,24 @@ static void msgHandler(QtMsgType type, const QMessageLogContext &context, const
void
AppMessages
::
installHandler
()
{
old_handler
=
qInstallMessageHandler
(
msgHandler
);
}
AppLogModel
*
AppMessages
::
getModel
()
{
return
&
AppLogModel
::
getModel
();
// Force creation of debug model on installing thread
Q_UNUSED
(
*
debug_model
);
}
AppLogModel
&
AppLogModel
::
getModel
()
AppLogModel
*
AppMessages
::
getModel
()
{
return
instance
;
return
debug_model
;
}
AppLogModel
::
AppLogModel
()
:
QStringListModel
()
{
#ifdef __mobile__
Qt
::
ConnectionType
contype
=
Qt
::
QueuedConnection
;
#else
Qt
::
ConnectionType
contype
=
Qt
::
AutoConnection
;
#endif
connect
(
this
,
&
AppLogModel
::
emitLog
,
this
,
&
AppLogModel
::
threadsafeLog
,
contype
);
}
void
AppLogModel
::
writeMessages
(
const
QUrl
dest_file
)
...
...
@@ -73,7 +78,7 @@ void AppLogModel::writeMessages(const QUrl dest_file)
const
QString
writebuffer
(
stringList
().
join
(
'\n'
).
append
(
'\n'
));
QtConcurrent
::
run
([
dest_file
,
writebuffer
]
{
emit
instance
.
writeStarted
();
emit
debug_model
->
writeStarted
();
bool
success
=
false
;
QFile
file
(
dest_file
.
toLocalFile
());
if
(
file
.
open
(
QIODevice
::
WriteOnly
|
QIODevice
::
Text
))
{
...
...
@@ -81,6 +86,18 @@ void AppLogModel::writeMessages(const QUrl dest_file)
out
<<
writebuffer
;
success
=
out
.
status
()
==
QTextStream
::
Ok
;
}
emit
instance
.
writeFinished
(
success
);
emit
debug_model
->
writeFinished
(
success
);
});
}
void
AppLogModel
::
log
(
const
QString
message
)
{
emit
debug_model
->
emitLog
(
message
);
}
void
AppLogModel
::
threadsafeLog
(
const
QString
message
)
{
const
int
line
=
rowCount
();
insertRows
(
line
,
1
);
setData
(
index
(
line
),
message
,
Qt
::
DisplayRole
);
}
src/QmlControls/AppMessages.h
View file @
a552bc72
...
...
@@ -27,21 +27,28 @@ This file is part of the QGROUNDCONTROL project
#include <QStringListModel>
#include <QUrl>
// Hackish way to force only this translation unit to have public ctor access
#ifndef _LOG_CTOR_ACCESS_
#define _LOG_CTOR_ACCESS_ private
#endif
class
AppLogModel
:
public
QStringListModel
{
Q_OBJECT
public:
static
AppLogModel
&
getModel
();
Q_INVOKABLE
void
writeMessages
(
const
QUrl
dest_file
);
static
void
log
(
const
QString
message
);
signals:
void
emitLog
(
const
QString
message
);
void
writeStarted
();
void
writeFinished
(
bool
success
);
private:
private
slots
:
void
threadsafeLog
(
const
QString
message
);
_LOG_CTOR_ACCESS_:
AppLogModel
();
static
AppLogModel
instance
;
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment