-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiary6.txt
782 lines (676 loc) · 20.2 KB
/
Diary6.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
【2019-05-04】shell
[shell baisc]
#https://blog.csdn.net/Michaelwubo/article/details/81698307
1.num=10(delcare a var,note that space is not allowed on both = side.)
2.declare -r NUM=10(declare a const, note that space is not allowed on both = side.)
3.num=$((num+10)) ($((exp)) exp calcuation need two( and one $, you can put space between ().)
4.let num=num+10(or let num+=10) (another way to do math calcuation use keyword let.)
5.num=$((num++)) num=$((++num)) (self increment or self decrement.)
6.
a=10.5
b=3.3
c=$(python -c "print $a+$b")
echo $c
(use python to do float calcuation a hack way.)
7.
cat<<MSG
This is a short message.
MSG
(print a message to the console)
[function]
1.declare and use a function
getDate()
{
date
return
}
getDate
output: 2019年 05月 04日 星期六 16:36:00 CST
2.delcare local var
name=king
testfunc()
{
local name=yang
return
}
testfunc
echo $name
output: king
3.pass var into a function
sumfunc()
{
local v1=$1
local v2=$2
local sum=$((v1+v2))
echo $sum
}
sumfunc 10 20
sum=$(sumfunc 10 20)
echo sum of 10 and 20 is $sum
output:
30
sum of 10 and 20 is 30
(first 30 produced by direct call, the second one collect the res into sum then use echo to output it)
[condition]
# https://www.cnblogs.com/wangcp-2014/p/6704375.html
1.receive input
read -p "what is your name " name
echo $name
2.condition branch
read -p "what is your age " age
echo your age is $age
if [ $age -eq 18 ]
then
echo you are just adult
elif [ $age -lt 18 ]
then
echo you are not adult
else
echo you are more than adult
fi
(note that 'then' can't be right after ']' unless you put a ';' after that ']'
and space must be contained between '[' and ']' also
'fi' must occur to indicate close of the condition branch)
another approch:
if [ $age -eq 18 ]; then echo you are just adult
elif [ $age -lt 18 ]; then echo you are not adult
else echo you are more than adult
you can put two '(' to a compartion with using '$' and '['
third approch:
if ((age == 18)); then echo you are just adult
elif ((age < 18)); then echo you are not adult
else echo you are more than adult
fi
one more example:
if (( (($age%2)) == 0 )); then echo your age is even
#if [ $(($age%2)) -eq 0 ]; then echo your age is even
else echo your age is odd
fi
string compare example:
str1=hello
str2=world
if [ $str1 = $str2 ]; then echo str1==str2
elif [[ $str1 < $str2 ]]; then echo str1\<str2
else echo str1\>str2
fi
output: str1<str2
note that if((exp)) is not useful for string compare
also for string compare '=' MUST be used, don't use '=='
if you use '<' or '>' for string double '[' --> '[[' is needed otherwise use '\<'
and string compare must use '=', '>', '<', -eq -nq... is not allowed
【2019-05-06】【1】XCode 共享文件夹
打开XCode工程 Info
添加一项 Application supports iTunes file sharing = TRUE
【2019-05-06】【2】Mac finder 显示全路径
打开终端输入: defaults write com.apple.finder _FXShowPosixPathInTitle -bool TRUE;killall Finder
【2019-05-12】【1】shell
1.regular expression compare
example:
read -p 'input a phone number: ' phone
phone_format='^[1-9][0-9]{10}$'
if [[ $phone =~ $phone_format ]]; then echo phone number is vaild
fi
input a phone number: 1234567891
output: phone number is vaild
2.IFS
IFS The Internal Field Separator that is used for word splitting after expansion and to split lines into words with the read builtin command.
The default value is space,tab,newline
example:
function test()
{
echo '\$* is '$*''
for arg in $*
do
echo $arg
done
}
args="this is a test message"
echo split paramters by space,tab,line
test $args
IFS=","
echo split paramters by ,
test $args
args="this,is,a,test,message"
test $args
output:
split paramters by space,tab,line
\$* is this is a test message
this
is
a
test
message
split paramters by ,
\$* is this is a test message
this is a test message
\$* is this is a test message
this
is
a
test
message
3.replacement for variable
replace string in var by using ${var// /}
[:alnum:] Alphanumeric characters.
[:alpha:] Alphabetic characters.
[:blank:] Space or tab characters.
[:cntrl:] Control characters.
[:digit:] Numeric characters.
[:graph:] Characters that are both printable and visible. (A space is printable, but not visible, while an a is both.)
[:lower:] Lower-case alphabetic characters.
[:print:] Printable characters (characters that are not control characters.)
[:punct:] Punctuation characters (characters that are not letter, digits, control characters, or space characters).
[:space:] Space characters (such as space, tab, and formfeed, to name a few).
[:upper:] Upper-case alphabetic characters.
[:digit:] Characters that are hexadecimal digits.
example:
args="this is a test message"
args=${args//t/T}
echo $args
#args=${args// /}
args=${args//[[:space:]]/}
echo $args
output:
This is a TesT message
ThisisaTesTmessage
【2019-05-12】【2】shell parameter expansion
1.if the variable is not declared use newvalue instead
${var-newvalue}
2.if the variable is not declared or the the vaule of variable is empty, use newvalue instead
${var:-newvalue}
3.if the variable is not declared use newvalue instead, also assign the value into variable
${var=newvalue}
4.if the variable is not declared or the the vaule of variable is empty, use newvalue instead
, also assign the value into variable
${var:=newvalue}
example:
name=
#if the variable of name is not declared use king instead
echo 'echo '${name-"king"}
#if the variable of name is not declared or the vaule of variable the is empty, use king instead
echo 'echo '${name:-"king"}
echo vaule of name is $name
echo '--------------------'
#if the variable of name2 is not declared use king instead also assign to name2
echo 'echo '${name2="king"}
echo vaule of name2 is $name2
echo '--------------------'
name3=
#if the variable of name3 is not declared or the the vaule of variable is emtpy, use king instead, also assign to name3
echo 'echo '${name3:="king"}
echo vaule of name3 is $name3
output:
echo
echo king
vaule of name is
--------------------
echo king
vaule of name2 is king
--------------------
echo king
vaule of name3 is king
【2019-05-12】【3】shell case
case $var in
# value could be a regular expression
value)
#do something if var is value
:;;
value2)
#do something if var is value2
:;;
*)
#fallback. do something for fallback case
:;;
esac
example:
read -p "input your age: " age
case $age in
[0-4])
echo "age is between 0 to 4";;
5)
echo "age is 5";;
[6-9]|1[0-2])
echo "age is between 6 to 12";;
#fallback
*)
echo "you age is above 12";;
esac
read -p "do you want to goto work? yes or no: " work
case $work in
yes)
echo "wow. you really want to goto work";;
no)
echo "yeah. i don't want to goto work either";;
*)
echo "your answer is not either yes or no";;
esac
input:25
output:you age is above 12
input:no
output:yeah. i don't want to goto work either
【2019-05-12】【4】ternary operator
(( exp ? (assigment for true) : (assigment for false) ))
example:
read -p "input your age: " age
(( age >= 18 ? (work=1) : (work=0) ))
if ((work)); then
echo you can you to work now
else
echo you can not go work. great
fi
input:25
output:you can you to work now
【2019-05-14】python metacalss
# https://www.cnblogs.com/iamswf/p/4713749.html
你可以在实现一个类的时候为其添加__metaclass__属性
这是该类的元类 类默认的元类是type
元类就是创建类对象的类 可以把元类看做"类工厂"
创建类对象时候python会在内存中通过__metaclass__创建类对象
如果python没有找到__metaclass__ 它会继续在父类中寻找__metaclass__ 以此类推
如果还是找不到__metaclass__ python就会用内置的type元类来创建这个类对象
例:
class MetaTest(type):
def __new__(mcs, name, bases, dict):
print "name: ", name
print "bases: ", bases
print "dict: ", dict
TEST_PROP = dict.get('TEST_PROP', '')
dict["TEST_PROP"] = "MODIFY TEST PROP"
return super(MetaTest, mcs).__new__(mcs, name, bases, dict)
class TestClass(object):
__metaclass__ = MetaTest
TEST_PROP = "TEST PROP"
if __name__ == '__main__':
t = TestClass()
print t.TEST_PROP
输出:
name: TestClass
bases: (<type 'object'>,)
dict: {'__module__': '__main__', '__metaclass__': <class '__main__.MetaTest'>, 'TEST_PROP': 'TEST PROP'}
MODIFY TEST PROP
【2019-05-17】【1】使用vnc远程连接mac
1.mac里在
用户偏好设置
共享->打开
屏幕共享
文件共享
远程登陆
2.安装VNC-Viewer
3.在VNC-Viewer登陆里输入ip登陆
【2019-05-17】【2】iOS开发证书
https://www.jianshu.com/p/f582683ef7a2
https://www.jianshu.com/p/194f581e0699
https://www.cnblogs.com/huangzizhu/p/4137571.html
https://blog.csdn.net/bolted_snail/article/details/80764572
1.bundle ID(APP ID)
是每一个ios应用的全球唯一标识
无论代码怎么改 图标和应用名称怎么换 只要bundle id没变 ios系统就认为这是同一个应用
bundle id分为两种 Explicit App ID 与 Wildcard App ID(使用这种id的应用不能使用通知功能)
2.iOS Certificates(证书)
它的作用就是证明你的mac具有开发或发布某个开发者账号下应用的权限
3.iOS Provisioning Profiles(描述文件)
描述文件它用来标识某个设备是否具有安装某个应用的权限
(简单来说就是应用和证书的关系 尤其注意证书和描述文件的过期日期 一旦过期应用就没法使用了)
【2019-05-17】【3】iOS 命令行重签
1.老的archive方式 不支持增量编译
xcodebuild archive \
-project *.xcodeproj \
-scheme Game \
-configuration $CONFIGURE \
-archivePath $ARCHIVE_PATH \
CODE_SIGN_IDENTITY='iPhone Developer' PROVISIONING_PROFILE='Automatic'
xcodebuild -exportArchive \
-archivePath $ARCHIVE_PATH \
-exportPath $PRODUCT_PATH \
-exportOptionsPlist ExportOptions.plist
原料文件ExportOptions.plist可以从通过GUI archive生成后的目标文件夹里找到
2.新的build方式 支持增量编译
# embedded.mobileprovision 从苹果开发者页面下载
# 从embedded.mobileprovision提取出Entitlements.plist保持embedded.mobileprovision
# 的Entitlements字段与Entitlements.plist一致
/usr/libexec/PlistBuddy -x -c "print :Entitlements " /dev/stdin <<< $(security cms -D -i embedded.mobileprovision) > Entitlements.plist
/usr/libexec/PlistBuddy -c "Set :get-task-allow true" Entitlements.plist
# 拷贝Info.plist 设置CFBundleIdentifier保证bundleID与embedded.mobileprovision一致
TEMP_INFO_PLIST=Info.plist.tmp
cp Info.plist $TEMP_INFO_PLIST
/usr/libexec/PlistBuddy -c "Set :CFBundleIdentifier $BUNDLE_IDENTIFIER" $TEMP_INFO_PLIST
/usr/libexec/PlistBuddy -c "Print :CFBundleIdentifier" $TEMP_INFO_PLIST
# 编译工程
xcodebuild -project *.xcodeproj -scheme $SCHEME -configuration $CONFIGURE
# 签名
codesign --force --sign "$DEVELOPER" --identifier $BUNDLE_IDENTIFIER --entitlements Entitlements.plist --timestamp=none $GAMEAPP_PATH
【2019-05-18】【1】 shell IFS 作用 echo
echo 分割后参数传给echo后以一整行输出
shell执行命令过程
1.替换变量
2.按照IFS参数划分命令参数(若参数以''或者""包围则当作一个参数)
3.执行命令
example:
string=" This is a test string "
echo "string:$string"
echo "before repalcing IFS"
# 没有使用""包括变量 IFS作用string头尾空格与单词之间多余空格被干掉
echo 'echo $string:'
echo $string
# 使用""包括变量 IFS没有作用
echo 'echo "$string:"'
echo "$string"
echo "after replacing IFS"
IFS=''
# 没有使用""包括变量 由于IFS为空
# string头尾空格与单词之间多余空格被保留
echo 'echo $string:'
echo $string
# 使用""包括变量 IFS没有作用
echo 'echo "$string:"'
echo "$string"
output:
string: This is a test string
before repalcing IFS
echo $string:
This is a test string
echo "$string:"
This is a test string
after replacing IFS
echo $string:
This is a test string
echo "$string:"
This is a test string
another example:
data="This,is,a,test"
echo $data
IFS=','
echo $data
output:
This,is,a,test
This is a test
【2019-05-18】【2】shell parameter expansion trick for string
1.get the of len fo a string
${#string}
2.splice the string
${string:$beg}
${string:$beg:$end}
3.get the after part of the substring in a string
${string#$substring}
exmaple:
string="This is a test string"
# get len of the string
echo "len of string is: ${#string}"
# get string from 5 to end
echo "${string:5}"
# get string from 0 to 4(not included)
echo "${string:0:4}"
# get string at the begin of string "a "
echo "${string#*"a "}"
output:
len of string is: 21
is a test string
This
test string
【2019-05-18】【3】shell looping
1.while loop
while [ condition ]; do
#continue
#break
done
example:
echo "use while condition"
# 1. while condition loop
# while [ $loopnum -lt $loopcount ]; do
while ((loopnum < loopcount)); do
echo "current loopnum is $loopnum"
# if (( $(($loopnum % 2)) == 0 )); then
# if (( (($loopnum % 2)) == 0 )); then
if (( ((loopnum % 2)) == 0 )); then
# loopnum=$(($loopnum + 1))
loopnum=$((loopnum + 1))
continue
fi
# if (($loopnum == 5)); then
if ((loopnum == 5)); then
echo "Is five !!!"
break
fi
loopnum=$((loopnum + 1))
done
ouput:
use while condition
current loopnum is 0
current loopnum is 1
current loopnum is 2
current loopnum is 3
current loopnum is 4
current loopnum is 5
Is five !!!
2.until loop
until [ condition ]; do
#continue
#break
done
example:
until ((loopnum >= loopcount)); do
echo "current loopnum is $loopnum"
if (( ((loopnum % 2)) == 0 )); then
loopnum=$((loopnum + 1))
continue
fi
if ((loopnum == 3)); then
echo "Is Three` !!!"
break
fi
loopnum=$((loopnum + 1))
done
output:
use until condition
current loopnum is 0
current loopnum is 1
current loopnum is 2
current loopnum is 3
Is Three !!!
【2019-05-18】【4】pipe doesn't work on read
read只支持命令行参数不支持管道(标准输入输出)
example:
echo 'cat testfile.txt'
cat testfile.txt
echo 'testfile.txt | wc'
cat testfile.txt | wc
echo "use pipe:"
echo 'cat testfile.txt | read content'
cat testfile.txt | read content
echo 'echo $content'
echo "$content"
echo "use redirection:"
echo 'content < testfile.txt'
read content < testfile.txt
echo 'echo $content'
echo "$content"
output:
cat testfile.txt
this is a test
testfile.txt | wc
1 4 15
use pipe:
cat testfile.txt | read content
echo $content
use redirection:
content < testfile.txt
echo $content
this is a test
【2019-05-18】【5】shell xargs
# https://www.runoob.com/linux/linux-comm-xargs.html
# https://segmentfault.com/q/1010000002962353/a-1020000002963602
有些命令如ls rm仅支持命令行参数 不支持标准输入
xargs可以将管道或标准输入(stdin)数据转换成命令行参数
example:
echo "testfile.txt" | xargs ls -la
cp testfile.txt testfile.txt.bak
echo "testfile.txt" | xargs rm -v
cp testfile.txt.bak testfile.txt
output:
-rw-r--r-- 1 king king 9 5月 18 22:36 testfile.txt
已删除'testfile.txt'
【2019-05-19】【1】shell 重定向
# https://www.runoob.com/linux/linux-shell-io-redirections.html
1.>(重定向程序输出到文件 覆盖原有内容)
example:
echo "this is a test message" | cat > testfile
# redirection
cat testfile > output.txt
cat output.txt
output:
this is a test message
2.>>(重定向程序输出到文件 追加原有内容)
example:
echo "this is a test message" | cat > testfile
# redirection
cat testfile > output.txt
cat testfile >> output.txt
cat output.txt
output:
this is a test message
this is a test message
3.<(以文件内容作为程序的标准输入)
example:
echo "this is a test message" | cat > testfile
cat < testfile
output:
this is a test message
4.<<tag(将开始标记 tag 和结束标记 tag 之间的内容作为程序的标准输入)
example:
cat << MSG
this is a test message
MSG
output:
this is a test message
5.<<<input(以input作为程序的标准输入)
example:
cat <<< "this is a test message"
output:
this is a test message
【2019-05-19】【2】shell 高级重定向
# https://www.cnblogs.com/caolisong/archive/2007/04/25/726896.html
一般情况下 每个 Unix/Linux 命令运行时都会打开三个文件:
标准输入文件(stdin):stdin的文件描述符为0 Unix程序默认从stdin读取数据
标准输出文件(stdout):stdout 的文件描述符为1 Unix程序默认向stdout输出数据
标准错误文件(stderr):stderr的文件描述符为2 Unix程序会向stderr流中写入错误信息
默认情况下, command > file 将 stdout 重定向到 file, command < file 将stdin 重定向到 file
如果希望 stderr 重定向到 file 可以这样写
command > file 2>&1
exmaple:
echo 'wc testfile > output.txt'
wc testfile > output.txt
echo 'cat output.txt'
cat output.txt
echo
echo 'wc testfile nonexistfile > output.txt'
wc testfile nonexistfile > output.txt
echo 'cat output.txt'
cat output.txt
echo
echo 'wc testfile nonexistfile 2> output.txt'
wc testfile nonexistfile 2> output.txt
echo 'cat output.txt'
cat output.txt
echo
echo 'wc testfile nonexistfile &> output.txt'
wc testfile nonexistfile &> output.txt
echo 'cat output.txt'
cat output.txt
echo
echo 'wc testfile nonexistfile > output.txt 2>&1'
wc testfile nonexistfile > output.txt 2>&1
echo 'cat output.txt'
cat output.txt
echo
echo 'wc testfile nonexistfile 2> output.txt 1>&2'
wc testfile nonexistfile 2> output.txt 1>&2
echo 'cat output.txt'
cat output.txt
output:
wc testfile > output.txt
cat output.txt
1 5 23 testfile
wc testfile nonexistfile > output.txt
wc: nonexistfile: 没有那个文件或目录
cat output.txt
1 5 23 testfile
1 5 23 总用量
wc testfile nonexistfile 2> output.txt
1 5 23 testfile
1 5 23 总用量
cat output.txt
wc: nonexistfile: 没有那个文件或目录
wc testfile nonexistfile &> output.txt
cat output.txt
1 5 23 testfile
wc: nonexistfile: 没有那个文件或目录
1 5 23 总用量
wc testfile nonexistfile > output.txt 2>&1
cat output.txt
1 5 23 testfile
wc: nonexistfile: 没有那个文件或目录
1 5 23 总用量
wc testfile nonexistfile 2> output.txt 1>&2
cat output.txt
1 5 23 testfile
wc: nonexistfile: 没有那个文件或目录
1 5 23 总用量
【2019-05-21】pyqt 信号
# https://www.linuxzen.com/pyqt4-xin-hao-he-cao-xiang-jie.html
# https://www.imooc.com/article/23738?block_id=tuijian_wz
pyqt支持多种声明信号的方式
1.在QObject类中定义QtCore.pyqtSignal类, 构造参数为其信号传递参数
然后调用QtCore.pyqtSignal.connect连接信号和槽,QtCore.pyqtSignal.emit发射信号
参数为信号传递参数
2.直接用QtCore.QObject.connect方法连接信号槽,在连接中定义信号形式
self.emit发射信号与信号参数
QtCore.QObject.connect(self, QtCore.SIGNAL('oldstyle_signal()'), self.slot)
self.emit(QtCore.SIGNAL('oldstyle_signal()'))
3.对于qt对象自带的内置信号,直接调用 self.'信号名'.connect 连接信号槽
例:
class TestWindow(QtGui.QMainWindow):
# 1. define new style signal, signal object MUST be in the class
str_signal = QtCore.pyqtSignal(QtCore.QString)
int_signel = QtCore.pyqtSignal(int)
def __init__(self, app):
QtGui.QMainWindow.__init__(self)
# 1. new style signal connection
self.str_signal.connect(self.strslot)
self.int_signel.connect(self.intslot)
# 1. new style signal emit
self.str_signal.emit("test new style signal msg")
self.int_signel.emit(100)
# 2. old style signal connection
QtCore.QObject.connect(self, QtCore.SIGNAL('oldstyle_str_signal(QString)'), self.strslot)
QtCore.QObject.connect(self, QtCore.SIGNAL('oldstyle_int_signal(int)'), self.intslot)
# 2. old style signal emit
self.emit(QtCore.SIGNAL('oldstyle_str_signal(QString)'), QtCore.QString("test old style signal msg"))
self.emit(QtCore.SIGNAL('oldstyle_int_signal(int)'), -100)
# 3. yet another style signal emit
self.btn = QtGui.QPushButton("TestBtn", self)
self.connect(self.btn, QtCore.SIGNAL("clicked()"), self.testSlot)
@pyqtSlot()
def testSlot(self):
print "test slot called"
@pyqtSlot(QtCore.QString)
def strslot(self, msg):
print "strslot:", msg
@pyqtSlot(int)
def intslot(self, val):
print "intslot:", val
class TestApp(QtGui.QApplication):
def __init__(self, arg):
super(TestApp, self).__init__(arg)
def init(self):
self.main_window = TestWindow(self)
self.main_window.show()
APP = TestApp(sys.argv)
def main():
APP.init()
sys.exit(APP.exec_())
输出:
strslot: test new style signal msg
intslot: 100
strslot: test old style signal msg
intslot: -100
test slot called (after you click the TestBtn)