void CDlgSmsPhone::FillData( ) { QString strSql = "select a.cardno, b.carcp, c.username, c.userphone from \ monthcard as a, carinfo as b, userinfo as c \ where a.cardno = b.cardindex and a.cardno = c.cardindex and \ c.userphone <> 'δ֪' and '1' = LEFT( c.userphone, 1 ) \ and 11 = CHAR_LENGTH( c.userphone )"; QStringList lstRows; CLogicInterface::GetInterface( )->ExecuteSql( strSql, lstRows ); QTableWidgetItem* pItem = NULL; for ( int nIndex = 0; nIndex < lstRows.size( ); nIndex += 4 ) { ui->tableWidget->insertRow( 0 ); for ( int nCol = 0; nCol < 5; nCol++ ) { if ( 4 != nCol ) { pItem = new QTableWidgetItem( lstRows[ nIndex + nCol ] ); } else { pItem = new QTableWidgetItem( ); pItem->setCheckState( Qt::Unchecked ); } ui->tableWidget->setItem( 0, nCol, pItem ); pItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled ); } } }
static VALUE tre_traverse(VALUE pattern, VALUE string, long char_offset, VALUE params, VALUE ignore_case, VALUE multi_line, int num_captures, VALUE repeat) { // Compile once regex_t preg; tre_compile_regex(&preg, pattern, ignore_case, multi_line); // Build regaparams regaparams_t aparams; tre_build_aparams(&aparams, params); // Match data regamatch_t match; regmatch_t pmatch[num_captures + 1]; // memset(&match, 0, sizeof(match)); match.nmatch = num_captures + 1; match.pmatch = pmatch; // Scan VALUE arr = rb_ary_new(); long char_offset_acc = char_offset; // rb_global_variable(&arr); while (1) { // Get substring to start with long char_len = CHAR_LENGTH(string) - char_offset; if (char_len <= 0) break; string = rb_str_substr(string, char_offset, char_len); int result = tre_reganexec(&preg, StringValuePtr(string), RSTRING_LEN(string), &match, aparams, 0); if (result == REG_NOMATCH) break; // Fill in array with ranges VALUE subarr; if (match.nmatch == 1) subarr = arr; // Faking.. kind of. else { subarr = rb_ary_new(); // rb_global_variable(&subarr); } unsigned int i; for (i = 0; i < match.nmatch; ++i) // No match if (match.pmatch[i].rm_so == -1) rb_ary_push(subarr, Qnil); // Match => Range else { VALUE range = rb_range_new( LONG2NUM( char_offset_acc + BYTE_TO_CHAR(string, match.pmatch[i].rm_so) ), LONG2NUM( char_offset_acc + BYTE_TO_CHAR(string, match.pmatch[i].rm_eo) ), 1); // rb_global_variable(&range); rb_ary_push(subarr, range); } if (match.nmatch > 1) rb_ary_push(arr, subarr); // Stop or proceed if (repeat == Qfalse) break; else { char_offset = BYTE_TO_CHAR(string, match.pmatch[0].rm_eo); if (char_offset == 0) char_offset = 1; // Weird case char_offset_acc += char_offset; } } // Free once tre_regfree(&preg); return arr; }