Skip to content

Commit 9d29eb3

Browse files
committedDec 7, 2021
Port QProcess::splitCommand for older qt
1 parent 4dc3a5e commit 9d29eb3

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed
 

‎src/crashhandler/qgscrashdialog.cpp

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,59 @@ void QgsCrashDialog::on_mUserFeedbackText_textChanged()
6565
mCopyReportButton->setEnabled( !mUserFeedbackText->toPlainText().isEmpty() );
6666
}
6767

68+
QStringList QgsCrashDialog::splitCommand( const QString &command )
69+
{
70+
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
71+
return QProcess::splitCommand( command );
72+
#else
73+
// taken from Qt 5.15's implementation
74+
QStringList args;
75+
QString tmp;
76+
int quoteCount = 0;
77+
bool inQuote = false;
78+
79+
// handle quoting. tokens can be surrounded by double quotes
80+
// "hello world". three consecutive double quotes represent
81+
// the quote character itself.
82+
for ( int i = 0; i < command.size(); ++i )
83+
{
84+
if ( command.at( i ) == QLatin1Char( '"' ) )
85+
{
86+
++quoteCount;
87+
if ( quoteCount == 3 )
88+
{
89+
// third consecutive quote
90+
quoteCount = 0;
91+
tmp += command.at( i );
92+
}
93+
continue;
94+
}
95+
if ( quoteCount )
96+
{
97+
if ( quoteCount == 1 )
98+
inQuote = !inQuote;
99+
quoteCount = 0;
100+
}
101+
if ( !inQuote && command.at( i ).isSpace() )
102+
{
103+
if ( !tmp.isEmpty() )
104+
{
105+
args += tmp;
106+
tmp.clear();
107+
}
108+
}
109+
else
110+
{
111+
tmp += command.at( i );
112+
}
113+
}
114+
if ( !tmp.isEmpty() )
115+
args += tmp;
116+
117+
return args;
118+
#endif
119+
}
120+
68121
void QgsCrashDialog::createBugReport()
69122
{
70123
QClipboard *clipboard = QApplication::clipboard();
@@ -77,7 +130,7 @@ void QgsCrashDialog::createBugReport()
77130

78131
void QgsCrashDialog::reloadQGIS()
79132
{
80-
const QStringList command = QProcess::splitCommand( mReloadArgs );
133+
const QStringList command = splitCommand( mReloadArgs );
81134
if ( command.isEmpty() )
82135
return;
83136

‎src/crashhandler/qgscrashdialog.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class QgsCrashDialog : public QDialog, private Ui::QgsCrashDialog
4747
void on_mUserFeedbackText_textChanged();
4848

4949
private:
50+
static QStringList splitCommand( const QString &command );
51+
5052
QString mReportData;
5153
QString mReloadArgs;
5254
};

0 commit comments

Comments
 (0)
Please sign in to comment.