Browse Source

Improve error checking

Neal Wilson 7 years ago
parent
commit
86d2ecdfdc
1 changed files with 23 additions and 1 deletions
  1. 23
    1
      src/roastcoloredit.w

+ 23
- 1
src/roastcoloredit.w View File

96
     QByteArray response = networkReply->readAll();
96
     QByteArray response = networkReply->readAll();
97
     networkReply->deleteLater();
97
     networkReply->deleteLater();
98
     networkReply = 0;
98
     networkReply = 0;
99
-    edit->setText(response.split('\n').last().split(',').at(2));
99
+    if(response.size() == 0)
100
+    {
101
+        return;
102
+    }
103
+    QList<QByteArray> lines = response.split('\n');
104
+    if(lines.last().size() == 0)
105
+    {
106
+        lines.removeLast();
107
+    }
108
+    if(lines.size() == 0)
109
+    {
110
+        return;
111
+    }
112
+    QList<QByteArray> fields = lines.last().split(',');
113
+    if(fields.size() < 3)
114
+    {
115
+        return;
116
+    }
117
+    edit->setText(QString(fields.at(2)));
100
 }
118
 }
101
 
119
 
102
 @ Two methods provide access to the |QLineEdit|.
120
 @ Two methods provide access to the |QLineEdit|.
119
 {
137
 {
120
     QBoxLayout *layout = qobject_cast<QBoxLayout *>(layoutStack->top());
138
     QBoxLayout *layout = qobject_cast<QBoxLayout *>(layoutStack->top());
121
     RoastColorEdit *edit = new RoastColorEdit;
139
     RoastColorEdit *edit = new RoastColorEdit;
140
+    if(element.hasAttribute("id"))
141
+    {
142
+        edit->setObjectName(element.attribute("id"));
143
+    }
122
     layout->addWidget(edit);
144
     layout->addWidget(edit);
123
 }
145
 }
124
 
146
 

Loading…
Cancel
Save