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
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
|
/****************************************************************************
**
** Copyright (C) 2022 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
** $QT_END_LICENSE$
**
****************************************************************************/
/*!
\page index.html
\nextpage Getting Started
\title Qt VS Tools Manual
Qt VS Tools integrate the Qt development tools into Microsoft Visual Studio
2017, and later. This enables developers to use the standard Windows
development environment without having to worry about Qt-related build steps
or tools. You can install and update Qt VS Tools directly from Microsoft
Visual Studio.
\table
\row
\li {4,1} \b {\l{All Topics}}
\row
\li \inlineimage front-gs.png
\li \inlineimage front-advanced.png
\li \inlineimage front-projects.png
\row
\li \b {\l{Getting Started}}
\list
\li \l {Tutorial: Qt Widgets Application}
\li \l {Tutorial: Qt Quick Application}
\endlist
\li \b {\l {Configuring Builds}}
\list
\li \l {Managing Qt Versions}
\li \l {Building}
\li \l {Cross-Compiling}
\li \l {Importing and Exporting Projects}
\endlist
\li \b {\l {Managing Projects}}
\list
\li \l {Creating Projects}
\li \l {Creating Files}
\endlist
\row
\li \inlineimage front-coding.png
\li \inlineimage front-preview.png
\li \inlineimage front-help.png
\row
\li \b {\l {Updating IntelliSense Info}}
\li \b {\l {Debugging}}
\list
\li \l {Debugging Qt Quick Applications}
\li \l {Debugging on Linux}
\endlist
\li \b {\l {Getting Help}}
\endtable
*/
/*!
\page qtvstools-toc.html
\title All Topics
\list
\li \l {Getting Started}
\list
\li \l {Tutorial: Qt Widgets Application}
\li \l {Tutorial: Qt Quick Application}
\endlist
\li \l {Configuring Builds}
\list
\li \l {Managing Qt Versions}
\li \l {Building}
\li \l {Cross-Compiling}
\li \l {Importing and Exporting Projects}
\endlist
\li \l {Managing Projects}
\list
\li \l {Creating Projects}
\li \l {Creating Files}
\list
\li \l {Adding Form Files}
\li \l {Managing Resources}
\li \l {Creating Qt Translation Files}
\endlist
\endlist
\li \l {Updating IntelliSense Info}
\li \l {Debugging}
\list
\li \l {Debugging Qt Quick Applications}
\li \l {Debugging on Linux}
\endlist
\li \l {Getting Help}
\endlist
*/
/*!
\page qtvstools-getting-started.html
\previouspage Qt VS Tools Manual
\nextpage Tutorial: Qt Widgets Application
\title Getting Started
The main features of Qt VS Tools are:
\list
\li Wizards for creating new Qt and Qt Quick projects and files.
\li Automated build setup for the \l {Using the Meta-Object Compiler
(moc)}{Meta-Object Compiler (moc)}, \l {User Interface Compiler
(uic)}, and \l {Resource Compiler (rcc)}.
\li Import and export of Qt project files (\c .pro) and project include
files (\c .pri).
\li Automated conversion of a Qt VS Tools project to a \l {qmake Manual}
{qmake} project, or the other way around.
\li Integrated Qt resource management.
\li Creating a Qt translation source (TS) file and starting Qt Linguist
to translate the strings.
\li Starting Qt Designer to design widget-based UIs for applications.
\li Integrated Qt documentation.
\li Debugging extensions for Qt data types.
\endlist
\section1 Install Qt VS Tools
In Microsoft Visual Studio, select \uicontrol Extensions >
\uicontrol {Manage Extensions} > \uicontrol Online,
and search for \uicontrol {Qt Visual Studio Tools}
to install or update Qt VS Tools.
\section1 Add a Qt Version
To create a Qt VS Tools project, you must add at least one
\l{Managing Qt Versions}{Qt version}.
\section1 Create a Project
Follow the tutorials to create your first applications:
\list
\li \l {Tutorial: Qt Widgets Application}
\li \l {Tutorial: Qt Quick Application}
\endlist
For all the options you have, see \l {Creating Projects}.
*/
/*!
\page qtvstools-qt-widgets-application.html
\previouspage Getting Started
\nextpage Tutorial: Qt Quick Application
\title Tutorial: Qt Widgets Application
This tutorial illustrates how to use Qt VS Tools to create a \l {Qt Widgets}
application. You will create a project using a project wizard and design a
widget-based UI using \QD. In addition, you will learn how to convert a
Microsoft Visual Studio project file into a qmake compatible \c .pro file.
You can use Qt VS Tools to develop also \l{Qt Quick} applications.
\section1 Before You Start
Before you start, you have to:
\list
\li \l {Install Qt VS Tools}
\li \l {Add a Qt Version}
\endlist
\section1 Create a Qt Widgets Application Project
To create a Qt Widgets application project in Visual Studio:
\list 1
\li Select \uicontrol File > \uicontrol New > \uicontrol Project, and
search for \uicontrol {Qt Widgets Application}.
\li Select the project wizard, and then select \uicontrol Next.
\li In the \uicontrol {Project name} field, enter \e AddressBook,
and then select \uicontrol OK.
\li To acknowledge the \uicontrol Welcome dialog, select
\uicontrol Next.
\li Set up the \uicontrol Debug build configuration and select the
modules to include in the project:
\image qtvstools-widgets-app-modules.png "Selecting Qt modules in Qt Widgets Application Wizard"
The modules that are typically needed in widget application projects
are selected by default.
\li Select \uicontrol Next to continue to the class creation page:
\image qtvstools-widgets-app-class.png "Creating a class in Qt Widgets Application Wizard"
\li In the \uicontrol {Base class} field, enter \uicontrol QWidget as
the base class type.
\li Select the \uicontrol {Lower case filenames} check box to
only use lower case characters in the names of the generated files.
\li Select the \uicontrol {Precompiled header} check box to use a
precompiled header file.
\li Select the \uicontrol {Add default application icon} check box to
use a default application icon for the application.
\li Select \uicontrol Finish to create the project.
\endlist
You now have a small working Qt application. Select \uicontrol Build >
\uicontrol {Build Solution} to build it, and then select \uicontrol Debug >
\uicontrol {Start Debugging} to run it. For now, the result is an empty
window.
\section1 Design the Main Window
You can use \QD to design the application's main window, which contains
some widgets placed in layouts:
\image qtvstools-addressbook-mainwindow.png AddressBook's main dialog
By default, \QD opens in Visual Studio. To open it as a stand-alone
application, select \uicontrol Detach.
To run \QD in a separate window by default, select \uicontrol Extensions >
\uicontrol {Qt VS Tools} > \uicontrol Options > \uicontrol {\QD}, and set
\uicontrol {Run in detached window} to \uicontrol True.
For more information about using \QD, see the \l{Qt Designer Manual}.
\section2 Add Widgets
To add widgets to the UI and to set properties for them:
\list 1
\li In Visual Studio's Solution Explorer, double-click the
\c addressbook.ui file to open it in \QD.
\li In \QD's \uicontrol Widgetbox, select \uicontrol {List Widget} and
drag and drop it to the form to add a \l QListWidget.
\li In the \uicontrol {Property Editor}, set the \c ObjectName property
to \e addressList.
\li Drag and drop two \uicontrol {Push Button} widgets to the top-right
corner of the form to add \l QPushButton objects for the
\uicontrol Add and \uicontrol Delete buttons.
\li Set the button names to \e addButton and \e deleteButton and
\uicontrol text property values to \e Add and \e Delete.
\li Drag and drop two \uicontrol {Label} widgets to the form to add
\l QLabel objects for displaying the selected item in the list.
\li Rename the first label to \e nameLabel and change its
\uicontrol text property to \e {<No item selected>}.
\li Rename the second label to \e emailLabel and leave its
\uicontrol text property empty.
\endlist
Position the widgets approximately as they appear in the screenshot above.
In order to properly position the widgets and to ensure that they are
resized correctly when the form is resized, you need to add layouts to the
form.
\section2 Add Widgets to Layouts
You will need a vertical layout for the buttons as well as a spacer to push
the buttons to the top of the layout. In addition, you will need a second
layout to manage the positioning of the other widgets as well as the button
layout.
To add wigdets to layouts:
\list 1
\li Drag a \uicontrol {Vertical Spacer} item to the form to add a
spacer.
\li Select the buttons and the spacer, and then select \uicontrol Form >
\uicontrol {Lay Out Vertically} to add a vertical layout
(\l QVBoxLayout).
\li Select the list widgets, the two labels, and the button layout,
and then select \uicontrol Form > \uicontrol {Lay Out in a Grid} to
add a grid layout (\l QGridLayout).
\note Make sure that the labels are almost as wide as the form.
Otherwise, the grid layout will make them only as wide as the
address list.
\li Select \uicontrol Form > \uicontrol Preview to preview your form
without compiling it.
\li Select \uicontrol File > \uicontrol Save to save the form.
\endlist
Build and run the application to check the main window.
\section1 Add a Dialog
Now that the main window is ready, you can move on to add functionality to
the application. To have the application open a dialog when the user clicks
the \uicontrol Add button, you must create an \uicontrol {Add Address}
dialog and invoke the dialog from a slot connected to the \uicontrol Add
button.
You can use a Qt file wizard in Visual Studio to create a UI form that
contains the \uicontrol OK and \uicontrol Cancel buttons connected to the
QDialog::accept() and QDialog::reject() slots, respectively. You can use \QD
to add other widgets to the form.
\section2 Create the Dialog
To add a dialog to a project:
\list 1
\li In Visual Studio, select \uicontrol Project >
\uicontrol {Add Qt Class} > \uicontrol Installed >
\uicontrol {Visual C++} > \uicontrol Qt >
\uicontrol {Qt Widgets Class}.
\li To acknowledge the \uicontrol Welcome dialog, select
\uicontrol Next.
\li In the \uicontrol Name field, enter \e AddDialog.
\image qtvstools-qt-widget-class-wizard.png "Creating a class in Qt Widgets Class Wizard"
\li In the \uicontrol {Base class} field, enter \uicontrol QDialog as
the base class type.
\li Select the \uicontrol {Multiple inheritance} radio button.
\li Select the \uicontrol {Lower case filenames} check box to
only use lower case characters in the names of the generated files.
\li Select \uicontrol Finish to create source, header, and UI files for
the dialog.
\endlist
\section2 Design the Dialog
\image qtvstools-addressbook-adddialog.png Add Address Dialog
To design the dialog:
\list 1
\li In Visual Studio's Solution Explorer, double-click the
\c adddialog.ui file to open it in \QD.
\li In \QD, set \e {Add Address} as the \uicontrol windowTitle.
\li Add a \uicontrol Label to the form and set its \uicontrol objectName
property to \e nameText and \uicontrol text property to \e {Name:}.
\li Add another \uicontrol Label and set its \uicontrol objectName
property to \e emailText and \uicontrol text property to
\e {Email:}.
\li Add a \uicontrol {Line Edit} (\l QLineEdit) and set its
\uicontrol objectName property to \e nameEdit. Leave the
\uicontrol text property empty.
\li Add another \uicontrol {Line Edit} and set its \uicontrol objectName
property to \e emailEdit. Leave the \uicontrol text property empty.
\li Select the labels and line edits, and then select \uicontrol Form >
\uicontrol {Lay Out in a Grid} to add a grid layout.
\li Add a \uicontrol {Push Button} and set its \uicontrol objectName
property to \e okButton and \uicontrol text property to \e OK.
\li Add a horizontal spacer to the left of the button.
\li Add a horizontal layout for the spacer and the button.
\li Add a vertical spacer between the labels and the button.
\li Add a vertical layout for the labels and the spacer.
\li Add a grid layout for both layouts.
\li Select \uicontrol Form > \uicontrol Preview to preview your form
without compiling it.
\li Select \uicontrol File > \uicontrol Save to save the form.
\endlist
\section1 Connect to the Dialog's OK Button
To have the \uicontrol OK button invoke the QDialog::accept() slot, click
the \uicontrol {Edit Signals/Slots} toolbar button to enter
\l {Qt Designer's Signals and Slots Editing Mode}.
Click the \uicontrol OK button, drag the mouse cursor to an empty area of
the form, and release the mouse button. In the
\uicontrol {Configure Connection} dialog, connect the button's
QPushButton::clicked() signal to the form's QDialog::accept() slot.
\section1 Open Dialogs from the Main Window
To invoke the dialog when the user selects \uicontrol Add in the main
window, you must add a slot to the \c AddressBook class and invoke
\c AddDialog from this slot.
Forms that are created using \QD call QMetaObject::connectSlotsByName() to
establish connections between signals emitted by the form's child widgets
and slots that follow the naming convention \c {on_<sender>_<signal>()}.
For the application to react appropriately when the \uicontrol Add button is
clicked, you must implement a slot called \c{on_addButton_clicked()}.
To implement the slot, open the \c addressbook.h file in Visual Studio and
add a declaration for the slot:
\badcode
private slots:
void on_addButton_clicked();
\endcode
Then open \c addressbook.cpp and add the slot definition:
\badcode
void AddressBook::on_addButton_clicked()
{
AddDialog dialog(this);
dialog.exec();
}
\endcode
To connect to some other signal, you must add the signal to the
\c AddressBook class. This requires editing both the header file,
\c addressbook.h, and the implementation file, \c addressbook.cpp.
Include \c adddialog.h to \c addressbook.cpp:
\quotefromfile AddressBook/addressbook.cpp
\skipto adddialog
\printuntil adddialog.h
To test your changes, build and run the application. Select the
\uicontrol Add button to open the \uicontrol {Add Address} dialog, and then
select \uicontrol OK to close it.
\section1 Add Items to the List Widget
When the user selects \uicontrol OK, an item should be added to the
QListWidget. To implement this function, modify the code in the
\c {on_addButton_clicked()} slot, as follows:
\skipto AddDialog dialog(this);
\printuntil }
\printuntil }
The dialog is executed. If the user accepts it by selecting \uicontrol OK,
the \uicontrol Name and \uicontrol Email fields are extracted and a
QListWidgetItem that contains the specified information is created.
\section1 Display the Selected Item
When the user selects an item in the list widget, the \c nameLabel and
\c emailLabel at the bottom of the form should be updated. This behavior
requires another slot to be added to the \c AddressBook class.
In the \c addressbook.h file, add the following code in the
\c{private slots} section of the class:
\quotefromfile AddressBook/addressbook.h
\skipto on_addressList_currentItemChanged()
\printuntil ;
Then, add the block of code below to \c addressbook.cpp:
\quotefromfile AddressBook/addressbook.cpp
\skipto on_addressList_currentItemChanged()
\printuntil /^\}/
Thanks to the naming convention, this slot will automatically be connected
to the QListWidget::currentItemChanged() signal of \c{addressList} and
invoked whenever the selected item in the list changes.
\section1 Add Functionality for the Delete Button
To implement a slot for the \uicontrol Delete button, open the
\c addressbook.h file in Visual Studio and add a declaration for the
\c on_deleteButton_clicked() slot. Then open \c addressbook.cpp and add the
slot definition for \c on_deleteButton_clicked().
Type the following code in the slot's body:
\skipto on_deleteButton_clicked()
\printuntil /^\}/
Your application is now complete.
\section1 Create Qt Project Files
To build the application on other platforms, you need to create a \c .pro
file for the project.
To let Qt VS Tools create a basic \c .pro file for you:
\list 1
\li Select \uicontrol Extensions > \uicontrol {Qt VS Tools} >
\uicontrol {Create Basic .pro File}.
\li In the \uicontrol {Export Project} dialog, make sure that the
\uicontrol {Create .pri file} check box is selected, and then select
\uicontrol OK.
\li Select \uicontrol Save to use the default location and name for
saving the \c .pri file.
\endlist
For more information about \c .pro files and their associated \c .pri files,
see \l {Creating Projects}.
You should now have a working \c .pro file and \c .pri file for your
project. For more complex projects, manually editing the \c .pro file
is required to make it work on all platforms. However, for the example
project, the generated \c .pro file is sufficient.
*/
/*!
\page qtvstools-qt-quick-application.html
\previouspage Tutorial: Qt Widgets Application
\nextpage Configuring Builds
\title Tutorial: Qt Quick Application
This tutorial illustrates how to use Qt VS Tools to create a \l {Qt Quick}
application. You will create a project using a project wizard and design a
Qt Quick UI. In addition, you will learn how to add QML module definitions
and QML files to your projects.
You can use Qt VS Tools to develop also \l{Qt Widgets} applications.
\section1 Before You Start
Before you start, you have to:
\list
\li \l {Install Qt VS Tools}
\li \l {Add a Qt Version}
\endlist
\section1 Create a Qt Quick Application Project
To create a Qt Quick application project in Visual Studio:
\list 1
\li Select \uicontrol File > \uicontrol New > \uicontrol Project, and
search for \uicontrol {Qt Quick Application}.
\li Select the project wizard, and then select \uicontrol Next.
\li In the \uicontrol {Project name} field, enter \e QuickAddressBook,
and then select \uicontrol Create.
\li To acknowledge the \uicontrol Welcome dialog, select
\uicontrol Next.
\li To set up debug and release build configurations, click in
\uicontrol {Quick Modules}, and select the \uicontrol {Quick} and
\uicontrol {Quick Controls2} modules to include in the project:
\image qtvstools-qtquick-app-modules.png "Selecting Qt modules in Qt Quick Application Wizard"
\li Select \uicontrol Finish to create the project.
\endlist
You now have a small working Qt Quick application. Select \uicontrol Build >
\uicontrol {Build Solution} to build it, and then select \uicontrol Debug >
\uicontrol {Start Debugging} to run it. For now, the result is an empty
window.
\section1 Design the Main Window
The wizard created a main QML file for you, which declares a root object of
the type \l Window. You can modify the file to design the application's main
window.
Specify values for the Window \c color and \c title properties to set the
background color and title of the application main window:
\quotefromfile QuickAddressBook/main.qml
\skipto Window {
\printuntil title
\section2 Add a Button
To create the \uicontrol Add button, declare an object of the \l Button type
from the \l {Qt Quick Controls} module. Set the value of the button \c text
property to \e Add and the value of the \c font.pointSize property to \e 24:
\skipto Button {
\printuntil font.pointSize
When you run the application, you should now see this:
\image qtvstools-quick-addressbook-mainwindow.png QuickAddressBook's main window
\section2 Connect the Button to an Action
QML has a signal and handler mechanism, where the signal is the event and
the signal is responded to through a signal handler. When a signal is
emitted, the corresponding signal handler is invoked. Placing logic such
as a script or other operations in the handler allows the component to
respond to the event.
To receive a notification when a particular signal is emitted for a
particular object, the object definition should declare a signal handler
named \c on<Signal>, where \c <Signal> is the name of the signal, with
the first letter capitalized. The signal handler should contain the
JavaScript code to be executed when the signal handler is invoked.
The \l Button type has a \c clicked signal, which is emitted when the users
click the button. To invoke a popup for adding an address book entry when
the users select the \uicontrol Add button in the main window, you must
connect the \c onClicked signal handler of the button to the \c open()
method of the popup. You will add the popup as a separate QML type later.
\printuntil }
\section2 Add a List Model
\image qtvstools-quick-addressbook-entries.png QuickAddressBook entries
Within the Window, declare an object of the \l ListModel type with the
\c id \e addressList for storing the contact data. A list model defines
a free-form list data source:
\quotefromfile QuickAddressBook/main.qml
\skipto ListModel {
\printuntil }
\section2 Declare a Popup
Declare an object of the custom \c NewAddressPopup type that
defines the popup where the users will add address book entries.
Use the \c onAddressAdded signal handler to determine that address
book entries are appended to the \e addressList model:
\printuntil }
\printuntil }
You will create the \c NewAddressPopup type later.
\section2 Position the Button
Declare an object of \l ColumnLayout type to position the \l Button object
and an instance of the \l Repeater type:
\printuntil }
Anchor the column layout to the left and right edges of its parent to make
the application scalable on different screen sizes. Set the \c spacing
between the rows in the column to \e 0.
\section2 Add a Repeater
The \l Repeater type is used to create a large number of similar items. It
has a model and a delegate: for each entry in the model, the delegate is
instantiated in a context seeded with data from the model. A repeater is
usually enclosed in an instance of a positioner type such as a
\l ColumnLayout to visually position the multiple delegate items created
by the repeater.
Specify \e addressList as the \c model to use for the repeater:
\printuntil anchors.right
Declare an object of the custom \c AddressBookItem type that the
repeater will use to instantiate address book entries:
\printuntil id:
You will create the \c AddressBookItem type later.
\section2 Connect the Remove Button to an Action
Use the \c onRemoved signal handler to specify that an address book entry
is removed from the list when the users click the \uicontrol Remove button
for an address book entry.
\printuntil }
\section1 Add a Popup
Now that the main window is ready, you can move on to create the popup
where users can add address book entries. The data that the
users enter is instantiated by the repeater in the main window, as
specified by the \c AddressBookItem type.
\image qtvstools-quick-addressbook-popup.png QuickAddressBook's popup
You can use a Qt file wizard in Visual Studio to create a custom type
that defines the popup.
To create custom QML types, you must first add a QML Module Definition
(\c qmldir) file to the project.
\section2 Add a QML Module Definition
A QML module definition (\c qmldir) maps each custom QML type to its
corresponding source file.
To add a QML module definition, select \uicontrol Project >
\uicontrol {Add New Item} > \uicontrol Qt >
\uicontrol {Qt QML Module Definition} > \uicontrol Add.
In the \c qmldir file, add QML type definitions for \e AddressBookItem and
\e NewAddressPopup:
\quotefile QuickAddressBook/qmldir
Next, you will create the QML types.
\section2 Create a Popup
To add a custom QML type to the project:
\list 1
\li Select \uicontrol Project > \uicontrol {Add New File} >
\uicontrol Qt > \uicontrol {Qt QML File} > \uicontrol Add.
\li In the \uicontrol Name field, enter \e NewAddressPopup.
\li Select \uicontrol Finish to create a custom QML type.
\endlist
\section2 Design the Popup
In \e NewAddressPopup.qml, declare a root object of the type \l Popup to
create a popup that can be opened within a \l Window. A popup does not
provide a layout of its own, so you will use a \l ColumnLayout and a
\l RowLayout to position the \uicontrol Name and \uicontrol {E-Mail Address}
fields.
\quotefromfile QuickAddressBook/QuickAddressBookTypes/NewAddressPopup.qml
\skipto Popup {
\printuntil id:
Set the \c modal property to \c true to specify that the popup is modal. Set
the \c focus property to \c true to specify that the popup requests focus:
\printuntil focus:
Specify values for the \c width, \c x, and \c y properties to determine the
position and size of the popup on top of the main window:
\printuntil y:
\section2 Reset Popup Controls
When the popup opens, the \uicontrol Name and \uicontrol {E-Mail Address}
fields should display placeholder text and any values entered previously
should be cleared. You use the \c onOpened signal handler to reset the
values of the fields and give focus to the \uicontrol Name field:
\printuntil }
\section2 Position Fields
Use an instance of the \l ColumnLayout type to position the \l TextField
objects that specify the \uicontrol Name and \uicontrol {E-Mail Address}
fields of the popup:
\skipto ColumnLayout {
\printuntil id: addrField
\printuntil }
\printuntil }
\section2 Position Buttons
Use an instance of a \l RowLayout type to position two \l Button objects
that specify the \uicontrol Add and \uicontrol Cancel buttons:
\printuntil Layout.fillWidth: true
\section2 Connect Buttons to Actions
When the users click the \uicontrol Add button, the values they entered to
the \uicontrol Name and \uicontrol {E-Mail Address} fields are added to the
address list in the main window and the popup is closed.
To enable this, add the \c {addressAdded(string newName, string newAddr)}
signal:
\quotefromfile QuickAddressBook/QuickAddressBookTypes/NewAddressPopup.qml
\skipto addressAdded(
\printuntil )
Connect the \c onClicked signal handler of the \uicontrol Add button to
the \c addressAdded() signal and to the popup's \c close() method:
\skipto Button {
\printuntil }
\printuntil }
For the \uicontrol Cancel button, connect the \c onClicked signal handler to
the to the popup's \c close() method to close the popup without saving the
data:
\printuntil }
\section1 Define an Address Book Entry
Address book entries are presented in the main window as specified by a
custom \c AddressBookItem type.
Select \uicontrol Project > \uicontrol {Add New File} > \uicontrol Qt >
\uicontrol {Qt QML File} > \uicontrol Add, to create a new QML file
called \e AddressBookItem.qml.
\section2 Design the Entry
First, you will declare a root object of type \l Rectangle. It is one of the
basic building blocks you can use to create an application in QML. Give it
an \c id to be able to refer to it later.
\quotefromfile QuickAddressBook/QuickAddressBookTypes/AddressBookItem.qml
\skipto Rectangle {
\printuntil id:
To use alternating colors for rows, set the value of the \c color property:
\printuntil color:
Anchor the rectangle to the left and right edges of its parent to make
the application scalable on different screen sizes. Bind the rectangle
\c height property to the height of the text items it will contain:
\printuntil height:
\section2 Connect the Remove Button to an Action
Add the \c removed() signal that you will connect to the \onClicked
signal handler of the remove button. This removes an address book entry
from the main window when users click the button:
\printuntil signal removed()
\section2 Position the Button and Text
Use instances of the \l RoundButton and \l Text types within an instance of
a \l RowLayout type to define an address book entry:
\printuntil }
\section2 Format the Text
Set the value of the \c text property to combine the values of the \c name
and \c addr fields from the popup and to use bold and italic formatting for
the values:
\printuntil }
Your application is now complete.
\section1 Create Project Files
To build the application on other platforms, you need to create a \c .pro
file for the project, as instructed in \l{Create Qt Project Files}.
*/
/*!
\page qtvstools-managing-projects.html
\previouspage Importing and Exporting Projects
\nextpage Creating Projects
\title Managing Projects
Qt VS Tools provides wizards for creating several types of Qt and Qt Quick
projects and files that you can add to the projects, such as classes, form
files, or custom QML types.
You can use the integrated Qt Resource editor to manage the resources in
Qt projects.
In addition, you can create a Qt translation source (TS) file and start
\QL from Visual Studio to translate the strings in your application.
\list
\li \l {Creating Projects}
\li \l {Creating Files}
\endlist
*/
/*!
\page qtvstools-creating-projects.html
\previouspage Managing Projects
\nextpage Creating Files
\title Creating Projects
Once you have installed Qt VS Tools, you can search for and then select
the following project templates in Visual Studio in \uicontrol File >
\uicontrol New \uicontrol Project:
\list
\li \uicontrol {Qt ActiveQt Server} creates a simple ActiveX server.
\li \uicontrol {Qt Class Library} creates a basic Qt-based dynamic
library.
\li \uicontrol {Qt Console Application} creates a basic Qt console
application.
\li \uicontrol {Qt Designer Custom Widget} creates a \QD custom widget
plugin.
\li \uicontrol {Qt Empty Application} creates a an empty Qt application
project.
\li \uicontrol {Qt Quick Application} creates a Qt Quick application
project.
\li \uicontrol {Qt Widgets Application} creates a simple Qt widgets
application with one form.
\endlist
Each Qt project provides a wizard that allows you to specify the Qt modules
required for your project. For some projects, the wizard will also generate
a skeleton class or QML type instance that you can use to get started.
To start writing Qt code and building your projects, you must tell Visual
Studio where to find the \l{Managing Qt Versions}{Qt version} that you want
to use.
The application tutorials contain examples of using the project templates:
\list
\li \l {Tutorial: Qt Widgets Application}
\li \l {Tutorial: Qt Quick Application}
\endlist
*/
/*!
\page qtvstools-creating-files.html
\previouspage Creating Projects
\nextpage Adding Form Files
\title Creating Files
You can use file templates to add the following types of files to projects
by selecting \uicontrol Project > \uicontrol {Add New Item} >
\uicontrol Installed > \uicontrol {Visual C++} > \uicontrol Qt:
\list
\li \uicontrol {Qt Class} adds a Qt class to an Application project.
\li \uicontrol {Qt Dialog Form File (Button Bottom)} adds a dialog with
\uicontrol OK and \uicontrol Cancel buttons at its bottom to a
Qt Widgets Application project.
\li \uicontrol {Qt Dialog Form File (Button Right)} adds a dialog with
buttons at its right edge to a Qt Widgets Application project.
\li \uicontrol {Qt MainWindow Form File} adds a form file to a
Qt Widgets Application project.
\li \uicontrol {Qt QML File} adds a custom QML type to a Qt Quick
Application project.
\li \uicontrol {Qt QML Module Definition} adds a qmldir file that
specifies the custom QML types used in a Qt Quick Application
project.
\li \uicontrol {Qt Resource File} adds a Qt resource file (.qrc) to
an Application project.
\li \uicontrol {Qt Translation File} adds a Qt translation file (.ts)
to an Application project.
\li \uicontrol {Qt Widget Class} adds a Qt Widgets class to a
Qt Widgets Application project.
\li \uicontrol {Qt Widget Form File} adds a Qt Widgets form file (.ui)
to an Application project.
\endlist
The following sections describe how to add different types of files to
projects:
\list
\li \l {Adding Form Files}
\li \l {Managing Resources}
\li \l {Creating Qt Translation Files}
\endlist
The application tutorials contain examples of using file templates to add
files to projects:
\list
\li \l {Tutorial: Qt Widgets Application}
\li \l {Tutorial: Qt Quick Application}
\endlist
*/
/*!
\page qtvstools-configuring-builds.html
\previouspage Tutorial: Qt Quick Application
\nextpage Managing Qt Versions
\title Configuring Builds
In Visual Studio, C++ projects are built using the Project System,
where MSBuild provides the project file format and build framework.
Qt VS Tools make use of the extensibility of MSBuild to provide
design-time and build-time integration of Qt in Visual Studio projects.
Qt uses \c .pro files with \l {qmake Manual}{qmake} to build projects,
whereas Visual Studio uses \c .vcproj files. Qt VS Tools enables you to
import Qt project files into Visual Studio and export them back into
Qt build files. In addition, you can convert Qt VS Tools projects into
a qmake project, or the other way around.
\list
\li \l {Managing Qt Versions}
\li \l {Building}
\li \l {Cross-Compiling}
\li \l {Importing and Exporting Projects}
\endlist
\section1 MSBuild Configurations
At very general level, MSBuild might be described as follows:
\list
\li An MSBuild project consists of references to source files and
descriptions of actions to take in order to process those source
files that are called \e targets.
\li The build process runs in the context of a project configuration,
such as \e Debug or \e Release. A project may contain any number
of configurations.
\li Data associated to source files and the project itself is accessible
through \e properties. MSBuild properties are name-value definitions,
specified per configuration. That is, each configuration has its own
set of property definitions.
\endlist
\image qtvstools-msbuild-diagram.png "Diagram showing Visual Studio Project and MSBuild"
\section2 Properties
Properties may apply to the project itself or to a specific file in the
project, and can be defined either globally or locally:
\list
\li Project scope properties are always global. For example, the
project's output directory or target file name.
\li Properties applied to source files can be defined globally, in
which case the same value will apply to all files. For example,
the default compiler warning level could be defined globally at
level 3.
\li Such a global, file-scope definition may be overridden for a
specific file by a locally defined property with the same name.
For example, one of the source files needs to be compiled with
warning level 4.
\li Global definitions are stored in the project file or imported from
property sheet files.
\li Local property definitions are stored in the project file, within
the associated source file references.
\endlist
\section2 Qt Settings
Qt Visual Studio Tools integrate with the MSBuild project system by
providing a set of Qt-specific targets that describe how to process
files such as moc headers by using the appropriate Qt tools.
\image qtvstools-qt-project-settings.png "Qt Project Settings"
Qt settings are fully-fledged project properties, which ensures that:
\list
\li Changes in Qt settings are synchronized with all the other
properties in the project.
\li You can specify Qt settings, such as Qt versions and modules,
separately for each build configuration.
\li You can override compiler properties for files generated by
Qt tools in project settings
\li You can share Qt settings within a team or organization by
exporting and importing them to and from shared \e {property sheet}
files (\c .props).
\endlist
*/
/*!
\page qtvstools-managing-qt-versions.html
\previouspage Configuring Builds
\nextpage Building
\title Managing Qt Versions
Qt VS Tools provide you with basic Qt version management that enables you to
use multiple Qt versions in parallel. For example, Qt 5.15.4 and 6.2.0.
You have to add at least one Qt version that was built for MSVC to be able
to create Qt projects.
\image qtvstools-qt-versions.png Qt Versions
To manage Qt versions:
\list 1
\li Select \uicontrol Extensions > \uicontrol {Qt VS Tools} >
\uicontrol {Qt Versions} > \inlineimage qtvstools-plus.png
.
\li In the \uicontrol Version field, enter a name for the Qt version.
If you add the path to Qt first, this field is filled automatically.
\li In the \uicontrol Host field, select \uicontrol Windows, unless you
want to cross-compile the application for an embedded Linux device.
\li In the \uicontrol Path field, enter the path to the qmake.exe for
the Qt version.
For example: \c {C:\Qt\6.2.0\msvc2019_64\bin\qmake.exe}.
\li In the \uicontrol Default field, select the Qt version to be used
by default when creating new projects or importing a project from a
\c {.pro} file.
\li Select \uicontrol OK.
\endlist
To remove a Qt version, select \inlineimage qtvstools-minus.png
.
To specify Qt versions for a project, right-click the project in Solution
Explorer and select \uicontrol Properties in the context menu. Select
\uicontrol {Qt Project Settings}, and set the Qt version as the value of
the \uicontrol {Qt Installation} option.
*/
/*!
\page qtvstools-building.html
\previouspage Managing Qt Versions
\nextpage Cross-Compiling
\title Building
Qt Visual Studio Tools includes MSBuild rules and targets specific to
\l {Using the Meta-Object Compiler (moc)}{Meta-Object Compiler (moc)},
\l {User Interface Compiler (uic)}, and \l {Resource Compiler (rcc)}.
These rules are referred to as \e Qt/MSBuild. They enable running moc,
rcc and uic in parallel processes and setting build options, such as
selecting project items to process and the tools to process them.
Further, source files generated by the Qt tools are added to the C++
compilation during the build process, so that generated files do not
need to be included in projects.
You can set options for each Qt tool either globally at project level
or for specific files. To set global options for handling files at project
level:
\list
\li Select \uicontrol Properties in the context menu of the project.
\li Select \uicontrol Extensions > \uicontrol {Qt VS Tools} >
\uicontrol {Qt Project Settings}.
\endlist
\image qtvstools-qt-project-settings.png "Qt Project Settings"
To set options for handling a specific file, select \uicontrol Properties
in the context menu of the file. Only tools relevant for the file type are
listed. For example, moc options are available for C++ source and header
files, whereas uic options are available for UI forms (.ui).
\section1 Project File Format
When importing .pro files, \e {custom build steps} are automatically
converted into Qt/MSBuild steps. To convert custom build steps into
Qt/MSBuild steps for a solution, select \uicontrol Qt >
\uicontrol {Convert custom build steps to Qt/MSBuild} in the context
menu of the solution.
The Qt/MSBuild project format has changed between Qt VS Tools versions, and
therefore you might have to manually update project files of imported
projects. For more information about Qt/MSBuild project format versions, see
\l {https://github.com/qt-labs/vstools/blob/dev/Tests/ProjectFormats/ProjectFormats.md}
{Qt VS Tools - Project format versions}.
\section1 Path to Build Files
To set the path to the Qt/MSBuild files, select \uicontrol Extensions >
\uicontrol {Qt VS Tools} > \uicontrol Options > \uicontrol {Qt/MSBuild}.
This corresponds to setting the value of the \c QTMSBUILDS environment
variable.
*/
/*!
\page qtvstools-cross-compiling.html
\previouspage Building
\nextpage Importing and Exporting Projects
\title Cross-Compiling
Qt VS Tools supports cross-compilation of Qt projects by integrating
Qt/MSBuild and the Linux development VS workload. This enables you to
develop widget-based and Qt Quick applications that target both Windows
and Linux, including embedded devices.
To develop Qt applications for Linux using Visual Studio:
\list
\li Install the Desktop development with C++ and Linux development with
C++ workloads.
\li Enable the Windows Subsystem for Linux (WSL) and install a
Linux distribution.
\li Alternatively, create a connection to a remote Linux build server.
\li Register the cross-compiled Qt build that resides in a WSL instance
or the remote build server.
\endlist
To add a Qt version for cross-compilation:
\list 1
\li Select \uicontrol Extensions > \uicontrol {Qt VS Tools} >
\uicontrol {Qt Versions} > \inlineimage qtvstools-plus.png
to add a new Qt version.
\li In the \uicontrol Version field, enter a name for the Qt version.
If you add the path to Qt first, this field is filled automatically.
\li In \uicontrol Host, select \uicontrol {Linux WSL} or
\uicontrol {Linux SSH}.
\li In the \uicontrol Path field, enter the path to the Qt installation.
\li In the \uicontrol Compiler field, enter the cross-compiler to use.
The default value is g++.
\endlist
\section1 Compiling on WSL
Using a WSL instance to run the cross-compiler is faster than using an
SSH connection to a build host. When using SSH, MSBuild must first upload
the source files to the remote host, whereas WSL mounts local drives in
\c /mnt, making file access instantaneous.
MSBuild assumes that paths specified in options are local paths and maps
them to corresponding Linux paths rooted on \c /mnt. For example:
\badcode
C:\include\foolib maps to /mnt/c/include/foolib
\endcode
Using absolute Linux paths as value of \uicontrol Extensions >
\uicontrol {Qt VS Tools} > \uicontrol Options > \uicontrol {Qt/MSBuild}
can lead to incorrect mappings. For example, \c {/home/user/raspi} maps
to \c {/mnt/home/user/raspi}.
To avoid this issue, create symbolic links in \c /mnt to other top-level
directories in the WSL instance file system.
*/
/*!
\page qtvstools-importing-and-exporting-projects.html
\previouspage Cross-Compiling
\nextpage Managing Projects
\title Importing and Exporting Projects
Qt and Visual Studio use different file formats to save projects. If you
build your application on multiple platforms, you probably already use
Qt \c .pro files with \l {qmake Manual}{qmake}. Otherwise, you might use
\c .vcproj files and Visual Studio to build your project, which is usually
more convenient for Windows-only development.
Qt VS Tools provide a way to combine both approaches so that you do not have
to manually maintain \c .pro files and \c .vcproj files in parallel. You
start by creating a \c .vcproj file, as usual. When you need a qmake
\c .pro file for storing Linux and macOS specific settings, select
\uicontrol Extensions > \uicontrol {Qt VS Tools} >
\uicontrol {Create Basic .pro File}.
\image qtvstools-export-project.png Export Projects dialog
If you have multiple Qt projects in one Visual Studio solution, the basic
\c .pro file generator can create a master \c .pro file of type \c subdirs
that includes all of the projects.
The generated \c .pro file is not meant to be a complete file, but a simple
starting point for porting to other platforms. However, these files
should be sufficient for compiling the skeleton projects created by the
predefined Qt project wizards. The \c .pro file includes a \c .pri file.
The \c .pri file contains the list of source files, header files, \c .ui
files, and \c .qrc files in the project. To generate the \c .pri file,
select \uicontrol Extensions > \uicontrol {Qt VS Tools} >
\uicontrol {Export Project to .pri File}.
When you add or remove a file from the Visual Studio project file, you must
regenerate the \c .pri file to ensure that the application can still be
built on other platforms.
Also, make sure that the \c .pri file included in the \c .pro file points to
the correct file. If you saved the \c .pri file using the suggested path and
name, this reference should be correct.
Developers on platforms other than Windows might add or remove files to the
project by editing the \c .pri file. When this happens, Windows developers
must select \uicontrol Extensions > \uicontrol {Qt VS Tools} >
\uicontrol {Import .pri File to Project} to synchronize the Visual Studio
project file with the \c .pri file.
If your project contains platform-specific source files, you should list
them in the \c .pro file so that they are not overwritten by Qt VS Tools.
To summarize, a cross-platform Qt project consists of the following files:
\list
\li A \c .vcproj file containing Windows-specific settings and listing
the files in the project.
\li A \c .pro file containing Linux and macOS specific settings.
\li A \c .pri file (a \c qmake include file) listing the files in the
project.
\endlist
If you already have a \c .pro file but no \c .vcproj file, select
\uicontrol Extensions > \uicontrol {Qt VS Tools} >
\uicontrol {Open Qt Project File (.pro)} to
convert your \c .pro file to a \c .vcproj file. The generated \c .vcproj
only contains Windows-specific settings. Also, there is no other way to
convert a \c .vcproj file back to the \c .pro file format than using the
\uicontrol {Create Basic .pro File} function.
*/
/*!
\page qtvstools-form-files.html
\previouspage Creating Files
\nextpage Managing Resources
\title Adding Form Files
You can start \QD from Qt VS Tools by double-clicking a \c .ui file. For
more information about using \QD, see the \l{Qt Designer Manual}.
To add a new \c .ui file to the project, select \uicontrol Project >
\uicontrol {Add New Item} > \uicontrol Installed > \uicontrol {Visual C++} >
\uicontrol Qt > \uicontrol {Qt Widgets Form File}.
\image qtvstools-qt-widget-class-wizard.png
Typically, you need to wrap the code generated for the form file into a
QWidget subclass to add signals or slots to it. Therefore, Qt VS Tools
create a \c .h and \c .cpp file for you, along with an empty UI form.
*/
/*!
\page qtvstools-managing-resources.html
\previouspage Adding Form Files
\nextpage Creating Qt Translation Files
\title Managing Resources
Adding new resources to a Qt project is similar to adding resources to a
normal C++ project. The main difference is that \c .qrc files (Qt
resource files) are used instead of Windows \c .rc files. Unlike \c .rc
files, \c .qrc files work on all platforms supported by Qt and are trivial
to load from Qt code.
\image qtvstools-qrc-editor.png Qt Resource Editor dialog
By default, Qt Resource Editor opens in Visual Studio. To run it in a
separate window, select \uicontrol Detach.
To run \uicontrol {Qt Resource Editor} in a separate window by default,
select \uicontrol Extensions > \uicontrol {Qt VS Tools} >
\uicontrol Options > \uicontrol {Qt Resource Editor}, and
set \uicontrol {Run in detached window} to \uicontrol True.
To add new resources:
\list 1
\li Select \uicontrol Project > \uicontrol {Add New Item} >
\uicontrol Installed > \uicontrol {Visual C++} > \uicontrol Qt >
\uicontrol {Qt Resource File}.
\li In the \uicontrol Name field, enter a name for the resource file.
\li In the \uicontrol Location field, specify a location for the file.
\li Select \uicontrol Add to create a \c .qrc file and to open it in the
\uicontrol {Qt Resource Editor}.
\li To add resources to the file, select \uicontrol Add >
\uicontrol {Add Files}.
\li In the \uicontrol Prefix field, you can change the prefix.
\endlist
When referring to the resources later on from Qt code, you must prepend the
prefix, the file name, and a colon. For example, \c{:/MyProject/print.bmp}.
To add prefixes to the \c .qrc file, select \uicontrol Add >
\uicontrol {Add Prefix} in the \uicontrol {Qt Resource Editor}.
For more information, see \l{The Qt Resource System}.
*/
/*!
\page qtvstools-translation-files.html
\previouspage Managing Resources
\nextpage Updating IntelliSense Info
\title Creating Qt Translation Files
To add a new translation file to the project:
\image qtvstools-qt-translation-file-wizard.png
\list 1
\li Select \uicontrol Project > \uicontrol {Add New Item} > \uicontrol Installed >
\uicontrol {Visual C++} > \uicontrol Qt > \uicontrol {Qt Translation File}.
\li In \uicontrol {Select a Language}, you can choose a language from the list
of supported languages. You can use \uicontrol Search to filter for a specific
language.
\li In the \uicontrol {Save as} field, enter a filename for the translation file.
\li Select \uicontrol Finish to create the file and have it listed in
\uicontrol {Translation Files} in Visual Studio's Solution Explorer.
\li Right-click a translation file to open a context menu with options
for running \c lupdate and \c lrelease.
\endlist
To start \QL, select \uicontrol Extensions > \uicontrol {Qt VS Tools} >
\uicontrol {Launch Qt Linguist} or double-click a \c .ts file in the
Solution Explorer.
By default, \QL opens in Visual Studio. To open it as a stand-alone
application, select \uicontrol Detach.
To run \QL in a separate window by default, select \uicontrol Extensions >
\uicontrol {Qt VS Tools} > \uicontrol Options > \uicontrol {\QL}, and set
\uicontrol {Run in detached window} to \uicontrol True.
For more information about Qt's translation tools, see the
\l {Qt Linguist Manual}.
*/
/*!
\page qtvstools-getting-help.html
\previouspage Debugging on Linux
\title Getting Help
By default, Qt VS Tools tries to display Qt online documentation when you
press \key F1. If you often end up in the Qt documentation even though you
wanted Microsoft documentation, you can turn off this feature and use the
default shortcut \key {Alt+F1}. Select \uicontrol Extensions >
\uicontrol {Qt VS Tools} > \uicontrol Options > \uicontrol Help, and set
\uicontrol {Try Qt documentation when F1 is pressed} to \uicontrol False
To read the documentation delivered with your Qt version instead of the
latest online version, set \uicontrol {Preferred source} to
\uicontrol Offline.
To set up another keyboard shortcut for Qt online help:
\list 1
\li Select \uicontrol Tools > \uicontrol Options >
\uicontrol Environment > \uicontrol Keyboard.
\li In the \uicontrol {Show commands containing} field, enter
\e {Help.F1Help}.
\li Select the \uicontrol {Press shortcut keys} field and press your
preferred keys to add them to the field.
\li Select \uicontrol Assign, and then select \uicontrol OK.
\endlist
*/
/*!
\page qtvstools-intellisense-info.html
\previouspage Creating Qt Translation Files
\nextpage Debugging
\title Updating IntelliSense Info
Visual Studio provides IntelliSense code editing features for C++ types
including code completion, parameter info, and member lists.
To keep IntelliSense info updated also with code generated by
Qt tools, such as \l {Using the Meta-Object Compiler (moc)}{moc},
\l {User Interface Compiler (uic)}{uic}, or \l {Resource Compiler (rcc)}
{rcc}, they are run in the background when source files change. If this
creates too much overhead for large solutions, you can disable the
\uicontrol {Run Qt tools in background build} option to only run
qmake and update a minimal set of Qt build properties.
If you disable the option and code completion does not work, try to rebuild
the project. You might have to wait some time before code completion fully
works after updating a source file. If rebuilding does not help, refresh the
code model by selecting \uicontrol {Rescan Solution} in the context menu of
the project.
To set options for updating IntelliSense info, select \uicontrol Extensions
> \uicontrol {Qt VS Tools} > \uicontrol Options > \uicontrol IntelliSense:
\list
\li \uicontrol {Auto project tracking} tracks changes and triggers a
background build of Qt targets when necessary.
\li \uicontrol {Show debug information} displays debug information about
IntelliSense info updates.
\li \uicontrol {Verbosity of background build log} determines the amount
of info recorded in the background build log.
\endlist
*/
/*!
\page qtvstools-debugging.html
\previouspage Updating IntelliSense Info
\nextpage Debugging Qt Quick Applications
\title Debugging
Visual Studio supports debugging Qt C++ applications using the Visual Studio
debugger and Qt Quick applications using the \e {QML debug engine}. To debug
applications on Linux, you can use GDB.
You can debug Qt and Qt Quick applications in Visual Studio by setting
breakpoints in C++ and QML files and stepping through the execution of code.
While in break mode, you can watch variables and change their values, as
well as evaluate arbitrary expressions. For Qt Quick applications, a QML
debugging session runs concurrently to a C++ debugging session, which
enables you to set breakpoints and watch variables in both C++ and QML
during the same debugging session.
To start a debugging session, select \uicontrol Debug >
\uicontrol {Start Debugging} or press \key F5.
\list
\li \l {Debugging Qt Quick Applications}
\li \l {Debugging on Linux}
\endlist
*/
/*!
\page qtvstools-debugging-qt-quick.html
\previouspage Debugging
\nextpage Debugging on Linux
\title Debugging Qt Quick Applications
A \e {QML debug engine} extends the Visual Studio debugger with features of
the \l{QML Debugging Infrastructure}{QML debugging infrastructure}, which is
a part of the \l{Qt QML} module that provides services for debugging,
inspecting, and profiling applications via a TCP port. The debug engine
implements interfaces from the Active Debugging 7 (AD7) extensibility
framework for the Visual Studio debugger.
If a Qt project contains QML resource files, starting a debugging session
(for example, by pressing \key F5) launches the native application and
connects to the QML debugging infrastructure of that application. This can
be seen in the Processes window of the Visual Studio debugger. Two processes
are listed: a native process that corresponds to the actual physical
process created for the C++ debugging session and a QML process that does
not correspond to any physical process that is running on the machine, but
rather represents the connection to the QML debugging runtime within the
native process.
The presence of both a native process and a QML process enables setting
breakpoints both in C++ or QML code. The Visual Studio debugger forwards
breakpoint requests to the appropriate debug engine. A filled circular
breakpoint marker in QML code indicates a valid breakpoint. This means that
a breakpoint request for that file position was sent to the QML runtime
and was confirmed by it.
When a breakpoint is hit, Visual Studio shows the current state of the call
stack. Unlike other scenarios of debugging applications that mix several
languages, such as .NET and native debugging, the QML debug engine does not
provide true mixed mode debugging. It runs concurrently with the native
debug engine and is not considered to be related to the native process by
the Visual Studio debugger. Therefore, even though you can debug both C++
and QML in the same debugging session, the stack that is shown when a QML
breakpoint is hit includes only QML function calls. The C++ context of those
calls will not be available.
As in the case of native debugging, while in break mode, it is possible to
view and modify the values of local variables in the context of the
currently active call stack frame, as well as to create watches for any
variable or expression. In the Immediate window, you can evaluate any
expression in the context of the current stack frame.
Move the mouse over a QML expression to display an instant watch window.
The value of that expression in the current context is displayed and can
be modified.
\section1 Enabling QML Debugging
QML debugging is enabled by default. To disable processing of all QML
debug events by the QML debug engine, select \uicontrol Extensions >
\uicontrol {Qt VS Tools} > \uicontrol Options > \uicontrol Qt
\uicontrol General > \uicontrol {QML Debugging}, and set
\uicontrol {Process debug events} to \uicontrol False.
This effectively excludes the QML debug engine from the debugging
environment and disables debugging of QML code for all projects.
\image qtvstools-options-qt-general.png "Qt General Options"
To increase or decrease the timeout for debugging connections in
milliseconds, edit the value of \uicontrol {Runtime connection timeout}.
To remove the timeout, set the value to \uicontrol Disabled.
For more information about debugging Qt Quick applications on Linux devices,
see \l {Remote QML Debugging}.
*/
/*!
\page qtvstools-debugging-linux.html
\previouspage Debugging Qt Quick Applications
\nextpage Getting Help
\title Debugging on Linux
If you have set up Qt VS Tools for \l {Cross-Compiling}{cross-compilation}
on Linux, you can debug applications running on a Linux devices. First
launch the application using \c gdbserver and then configure GDB to connect
to the device and start a remote debugging session.
\image qtvstools-remote-debugging.png
For this to work, the GDB installed in the WSL must support the target
device architecture. A simple way to achieve this is to install
\c gdb-multiarch. To ensure the Visual Studio uses the correct debugger,
create a symbolic link from \c gdb to \c gdb-multiarch.
To set up the remote debugging session in Visual Studio, you must
pass additional commands to GDB. Select \uicontrol Project >
\uicontrol Properties > \uicontrol Debugging, and then select
\uicontrol {GDB Debugger} in \uicontrol {Debugger to launch}. In
\uicontrol {Additional Debugger Commands}, add the following commands:
\badcode
target extended-remote <IP_address>:<port>
set remote exec-file <path_to_executable>
\endcode
Before starting the remote debugging session, set the required environment
variables and launch \c gdbserver on the device:
\list
\li \l{https://man7.org/linux/man-pages/man8/ld.so.8.html}
{LD_LIBRARY_PATH} specifies the path to the directory
where Qt binaries are installed.
\li \l {Qt for Embedded Linux}{QT_QPA_PLATFORM} specifies the platform
plugin, such as EGLFS, LinuxFB, DirectFB, or Wayland.
\li \c QT_QPA_PLATFORM_PLUGIN_PATH specifies the path to the
directory where the platform plugin is installed.
\li For the \l {EGLFS} platform, \c QT_QPA_EGLFS_PHYSICAL_WIDTH and
\c QT_QPA_EGLFS_PHYSICAL_HEIGHT specify the screen width and
height in millimeters.
\li \l{QML Import Path}{QML2_IMPORT_PATH} specifies the path to the
directory where QML modules are installed.
\endlist
Press \key F5 to start the remote debugging session.
\section1 Remote QML Debugging
To debug Qt Quick applications on Linux devices, \l{Enabling QML Debugging}
{enable QML debugging} and set up program arguments for starting a QML
debugging session. \uicontrol Project > \uicontrol Properties >
\uicontrol Debugging, and then select \uicontrol {GDB Debugger} in
\uicontrol {Debugger to launch}. In
\uicontrol {Additional Debugger Commands}, add the following command:
\badcode
-qmljsdebugger=port:<port>,host:<IP_address>,block
\endcode
*/
|