如何使用Microsoft Excel Object Library实现整行及多行copy,Past

hhqing 2004-08-27 12:54:41
使用Microsoft Excel Object Library可是实现整个Sheet的拷贝.
如何实现使用Microsoft Excel Object Library实现整行及多行(连续的)copy,Past
...全文
105 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhuomaocn 2004-08-27
  • 打赏
  • 举报
回复
你只要申明了对象就可以用啊
比如

Set xlApp = server.CreateObject("Excel.Application")
strsource = "c:excelook1.xls"
Set xlbook = xlApp.Workbooks.Open(strsource)
Set xlsheet = xlbook.Worksheets(1)
...
hhqing 2004-08-27
  • 打赏
  • 举报
回复
我现在是在ASP中使用,使用VBScript,这样可以吗?
zhuomaocn 2004-08-27
  • 打赏
  • 举报
回复
1. 你说的不错,开始行号,终了行号的意思

2. 不同页面间插入的例子
Rows("5:6").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Sheet2").Select
Rows("7:7").Select
Selection.Insert(-4121)
hhqing 2004-08-27
  • 打赏
  • 举报
回复
谢谢,Rows("n:m")是不是代表从n行到m行,还有如果是在两个SHEET间使用的话,那么是不是在操作之前要ACTIVE相应的SHEET?
zhuomaocn 2004-08-27
  • 打赏
  • 举报
回复
插入:
Rows("4:5").Select
Selection.Copy
Rows("7:7").Select
Selection.Insert(-4121) '-4121可以不要
删除
Rows("7:8").Select
Selection.Delete(-4162) '-4162可以不要
hhqing 2004-08-27
  • 打赏
  • 举报
回复
如何实现多行的插入?
hhqing 2004-08-27
  • 打赏
  • 举报
回复
如何实现多行的删除?谢谢
zhuomaocn 2004-08-27
  • 打赏
  • 举报
回复
Rows("3:4").Select
Selection.Copy
Rows("7:7").Select
ActiveSheet.Paste
# Sortable Sortable is a minimalist JavaScript library for reorderable drag-and-drop lists. Demo: http://rubaxa.github.io/Sortable/ ## Features * Supports touch devices and [modern](http://caniuse.com/#search=drag) browsers (including IE9) * Can drag from one list to another or within the same list * CSS animation when moving items * Supports drag handles *and selectable text* (better than voidberg's html5sortable) * Smart auto-scrolling * Built using native HTML5 drag and drop API * Supports * [Meteor](https://github.com/SortableJS/meteor-sortablejs) * AngularJS * [2.0+](https://github.com/SortableJS/angular-sortablejs) * [1.*](https://github.com/SortableJS/angular-legacy-sortablejs) * React * [ES2015+](https://github.com/SortableJS/react-sortablejs) * [Mixin](https://github.com/SortableJS/react-mixin-sortablejs) * [Knockout](https://github.com/SortableJS/knockout-sortablejs) * [Polymer](https://github.com/SortableJS/polymer-sortablejs) * [Vue](https://github.com/SortableJS/Vue.Draggable) * Supports any CSS library, e.g. [Bootstrap](#bs) * Simple API * [CDN](#cdn) * No jQuery (but there is [support](#jq))
### Articles * [Sortable v1.0 — New capabilities](https://github.com/RubaXa/Sortable/wiki/Sortable-v1.0-—-New-capabilities/) (December 22, 2014) * [Sorting with the help of HTML5 Drag'n'Drop API](https://github.com/RubaXa/Sortable/wiki/Sorting-with-the-help-of-HTML5-Drag'n'Drop-API/) (December 23, 2013)
### Install Via npm ```bash $ npm install sortablejs --save ``` Via bower: ```bash $ bower install --save sortablejs ```
### Usage ```html
  • item 1
  • item 2
  • item 3
``` ```js var el = document.getElementById('items'); var sortable = Sortable.create(el); ``` You can use any element for the list and its elements, not just `ul`/`li`. Here is an [example with `div`s](http://jsbin.com/qumuwe/edit?html,js,output). --- ### Options ```js var sortable = new Sortable(el, { group: "name", // or { name: "...", pull: [true, false, clone], put: [true, false, array] } sort: true, // sorting inside list delay: 0, // time in milliseconds to define when the sorting should start touchStartThreshold: 0, // px, how many pixels the point should move before cancelling a delayed drag event disabled: false, // Disables the sortable if set to true. store: null, // @see Store animation: 150, // ms, animation speed moving items when sorting, `0` — without animation handle: ".my-handle", // Drag handle selector within list items filter: ".ignore-elements", // Selectors that do not lead to dragging (String or Function) preventOnFilter: true, // Call `event.preventDefault()` when triggered `filter` draggable: ".item", // Specifies which items inside the element should be draggable ghostClass: "sortable-ghost", // Class name for the drop placeholder chosenClass: "sortable-chosen", // Class name for the chosen item dragClass: "sortable-drag", // Class name for the dragging item dataIdAttr: 'data-id', forceFallback: false, // ignore the HTML5 DnD behaviour and force the fallback to kick in fallbackClass: "sortable-fallback", // Class name for the cloned DOM Element when using forceFallback fallbackOnBody: false, // Appends the cloned DOM Element into the Document's Body fallbackTolerance: 0, // Specify in pixels how far the mouse should move before it's considered as a drag. scroll: true, // or HTMLElement scrollFn: function(offsetX, offsetY, originalEvent, touchEvt, hoverTargetEl) { ... }, // if you have custom scrollbar scrollFn may be used for autoscrolling scrollSensitivity: 30, // px, how near the mouse must be to an edge to start scrolling. scrollSpeed: 10, // px setData: function (/** DataTransfer */dataTransfer, /** HTMLElement*/dragEl) { dataTransfer.setData('Text', dragEl.textContent); // `dataTransfer` object of HTML5 DragEvent }, // Element is chosen onChoose: function (/**Event*/evt) { evt.oldIndex; // element index within parent }, // Element dragging started onStart: function (/**Event*/evt) { evt.oldIndex; // element index within parent }, // Element dragging ended onEnd: function (/**Event*/evt) { var itemEl = evt.item; // dragged HTMLElement evt.to; // target list evt.from; // previous list evt.oldIndex; // element's old index within old parent evt.newIndex; // element's new index within new parent }, // Element is dropped into the list from another list onAdd: function (/**Event*/evt) { // same properties as onEnd }, // Changed sorting within list onUpdate: function (/**Event*/evt) { // same properties as onEnd }, // Called by any change to the list (add / update / remove) onSort: function (/**Event*/evt) { // same properties as onEnd }, // Element is removed from the list into another list onRemove: function (/**Event*/evt) { // same properties as onEnd }, // Attempt to drag a filtered element onFilter: function (/**Event*/evt) { var itemEl = evt.item; // HTMLElement receiving the `mousedown|tapstart` event. }, // Event when you move an item in the list or between lists onMove: function (/**Event*/evt, /**Event*/originalEvent) { // Example: http://jsbin.com/tuyafe/1/edit?js,output evt.dragged; // dragged HTMLElement evt.draggedRect; // TextRectangle {left, top, right и bottom} evt.related; // HTMLElement on which have guided evt.relatedRect; // TextRectangle originalEvent.clientY; // mouse position // return false; — for cancel }, // Called when creating a clone of element onClone: function (/**Event*/evt) { var origEl = evt.item; var cloneEl = evt.clone; } }); ``` --- #### `group` option To drag elements from one list into another, both lists must have the same `group` value. You can also define whether lists can give away, give and keep a copy (`clone`), and receive elements. * name: `String` — group name * pull: `true|false|'clone'|function` — ability to move from the list. `clone` — copy the item, rather than move. * put: `true|false|["foo", "bar"]|function` — whether elements can be added from other lists, or an array of group names from which elements can be taken. * revertClone: `boolean` — revert cloned element to initial position after moving to a another list. Demo: - http://jsbin.com/naduvo/edit?js,output - http://jsbin.com/rusuvot/edit?js,output — use of complex logic in the `pull` and` put` - http://jsbin.com/magogub/edit?js,output — use `revertClone: true` --- #### `sort` option Sorting inside list. Demo: http://jsbin.com/videzob/edit?html,js,output --- #### `delay` option Time in milliseconds to define when the sorting should start. Demo: http://jsbin.com/xizeh/edit?html,js,output --- #### `touchStartThreshold` option This option is similar to `fallbackTolerance` option. When the `delay` option is set, some phones with very sensitive touch displays like the Samsung Galaxy S8 will fire unwanted touchmove events even when your finger is not moving, resulting in the sort not triggering. This option sets the minimum pointer movement that must occur before the delayed sorting is cancelled. Values between 3 to 5 are good. --- #### `disabled` options Disables the sortable if set to `true`. Demo: http://jsbin.com/xiloqu/edit?html,js,output ```js var sortable = Sortable.create(list); document.getElementById("switcher").onclick = function () { var state = sortable.option("disabled"); // get sortable.option("disabled", !state); // set }; ``` --- #### `handle` option To make list items draggable, Sortable disables text selection by the user. That's not always desirable. To allow text selection, define a drag handler, which is an area of every list element that allows it to be dragged around. Demo: http://jsbin.com/newize/edit?html,js,output ```js Sortable.create(el, { handle: ".my-handle" }); ``` ```html
  • :: list item text one
  • :: list item text two
``` ```css .my-handle { cursor: move; cursor: -webkit-grabbing; } ``` --- #### `filter` option ```js Sortable.create(list, { filter: ".js-remove, .js-edit", onFilter: function (evt) { var item = evt.item, ctrl = evt.target; if (Sortable.utils.is(ctrl, ".js-remove")) { // Click on remove button item[removed].removeChild(item); // remove sortable item } else if (Sortable.utils.is(ctrl, ".js-edit")) { // Click on edit link // ... } } }) ``` --- #### `ghostClass` option Class name for the drop placeholder (default `sortable-ghost`). Demo: http://jsbin.com/hunifu/4/edit?css,js,output ```css .ghost { opacity: 0.4; } ``` ```js Sortable.create(list, { ghostClass: "ghost" }); ``` --- #### `chosenClass` option Class name for the chosen item (default `sortable-chosen`). Demo: http://jsbin.com/hunifu/3/edit?html,css,js,output ```css .chosen { color: #fff; background-color: #c00; } ``` ```js Sortable.create(list, { delay: 500, chosenClass: "chosen" }); ``` --- #### `forceFallback` option If set to `true`, the Fallback for non HTML5 Browser will be used, even if we are using an HTML5 Browser. This gives us the possibility to test the behaviour for older Browsers even in newer Browser, or make the Drag 'n Drop feel more consistent between Desktop , Mobile and old Browsers. On top of that, the Fallback always generates a copy of that DOM Element and appends the class `fallbackClass` defined in the options. This behaviour controls the look of this 'dragged' Element. Demo: http://jsbin.com/yacuqib/edit?html,css,js,output --- #### `fallbackTolerance` option Emulates the native drag threshold. Specify in pixels how far the mouse should move before it's considered as a drag. Useful if the items are also clickable like in a list of links. When the user clicks inside a sortable element, it's not uncommon for your hand to move a little between the time you press and the time you release. Dragging only starts if you move the pointer past a certain tolerance, so that you don't accidentally start dragging every time you click. 3 to 5 are probably good values. --- #### `scroll` option If set to `true`, the page (or sortable-area) scrolls when coming to an edge. Demo: - `window`: http://jsbin.com/tutuzeh/edit?html,js,output - `overflow: hidden`: http://jsbin.com/kolisu/edit?html,js,output --- #### `scrollFn` option Defines function that will be used for autoscrolling. el.scrollTop/el.scrollLeft is used by default. Useful when you have custom scrollbar with dedicated scroll function. --- #### `scrollSensitivity` option Defines how near the mouse must be to an edge to start scrolling. --- #### `scrollSpeed` option The speed at which the window should scroll once the mouse pointer gets within the `scrollSensitivity` distance. --- ### Event object ([demo](http://jsbin.com/xedusu/edit?js,output)) - to:`HTMLElement` — list, in which moved element. - from:`HTMLElement` — previous list - item:`HTMLElement` — dragged element - clone:`HTMLElement` - oldIndex:`Number|undefined` — old index within parent - newIndex:`Number|undefined` — new index within parent #### `move` event object - to:`HTMLElement` - from:`HTMLElement` - dragged:`HTMLElement` - draggedRect:` TextRectangle` - related:`HTMLElement` — element on which have guided - relatedRect:` TextRectangle` --- ### Method ##### option(name:`String`[, value:`*`]):`*` Get or set the option. ##### closest(el:`String`[, selector:`HTMLElement`]):`HTMLElement|null` For each element in the set, get the first element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree. ##### toArray():`String[]` Serializes the sortable's item `data-id`'s (`dataIdAttr` option) into an array of string. ##### sort(order:`String[]`) Sorts the elements according to the array. ```js var order = sortable.toArray(); sortable.sort(order.reverse()); // apply ``` ##### save() Save the current sorting (see [store](#store)) ##### destroy() Removes the sortable functionality completely. ---
### Store Saving and restoring of the sort. ```html
  • order
  • save
  • restore
``` ```js Sortable.create(el, { group: "localStorage-example", store: { /** * Get the order of elements. Called once during initialization. * @param {Sortable} sortable * @returns {Array} */ get: function (sortable) { var order = localStorage.getItem(sortable.options.group.name); return order ? order.split('|') : []; }, /** * Save the order of elements. Called onEnd (when the item is dropped). * @param {Sortable} sortable */ set: function (sortable) { var order = sortable.toArray(); localStorage.setItem(sortable.options.group.name, order.join('|')); } } }) ``` --- ### Bootstrap Demo: http://jsbin.com/qumuwe/edit?html,js,output ```html <!-- Latest compiled and minified CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css"/> <!-- Latest Sortable --> [removed][removed] <!-- Simple List -->
  • This is Sortable
  • It works with Bootstrap...
  • ...out of the box.
  • It has support for touch devices.
  • Just drag some elements around.
[removed] // Simple list Sortable.create(simpleList, { /* options */ }); [removed] ``` --- ### Static methods & properties ##### Sortable.create(el:`HTMLElement`[, options:`Object`]):`Sortable` Create new instance. --- ##### Sortable.active:`Sortable` Link to the active instance. --- ##### Sortable.utils * on(el`:HTMLElement`, event`:String`, fn`:Function`) — attach an event handler function * off(el`:HTMLElement`, event`:String`, fn`:Function`) — remove an event handler * css(el`:HTMLElement`)`:Object` — get the values of all the CSS properties * css(el`:HTMLElement`, prop`:String`)`:Mixed` — get the value of style properties * css(el`:HTMLElement`, prop`:String`, value`:String`) — set one CSS properties * css(el`:HTMLElement`, props`:Object`) — set more CSS properties * find(ctx`:HTMLElement`, tagName`:String`[, iterator`:Function`])`:Array` — get elements by tag name * bind(ctx`:Mixed`, fn`:Function`)`:Function` — Takes a function and returns a new one that will always have a particular context * is(el`:HTMLElement`, selector`:String`)`:Boolean` — check the current matched set of elements against a selector * closest(el`:HTMLElement`, selector`:String`[, ctx`:HTMLElement`])`:HTMLElement|Null` — for each element in the set, get the first element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree * clone(el`:HTMLElement`)`:HTMLElement` — create a deep copy of the set of matched elements * toggleClass(el`:HTMLElement`, name`:String`, state`:Boolean`) — add or remove one classes from each element --- ### CDN ```html <!-- jsDelivr :: Sortable (https://www.jsdelivr.com/package/npm/sortablejs) --> [removed][removed] <!-- jsDelivr :: Sortable :: Latest (https://www.jsdelivr.com/package/npm/sortablejs) --> [removed][removed] ``` --- ### jQuery compatibility To assemble plugin for jQuery, perform the following steps: ```bash cd Sortable npm install grunt jquery ``` Now you can use `jquery.fn.sortable.js`:
(or `jquery.fn.sortable.min.js` if you run `grunt jquery:min`) ```js $("#list").sortable({ /* options */ }); // init $("#list").sortable("widget"); // get Sortable instance $("#list").sortable("destroy"); // destroy Sortable instance $("#list").sortable("{method-name}"); // call an instance method $("#list").sortable("{method-name}", "foo", "bar"); // call an instance method with parameters ``` And `grunt jquery:mySortableFunc` → `jquery.fn.mySortableFunc.js` --- ### Contributing (Issue/PR) Please, [read this](CONTRIBUTING.md). --- ## MIT LICENSE Copyright 2013-2017 Lebedev Konstantin http://rubaxa.github.io/Sortable/ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FastReport.v4.15 for.Delphi.BCB.Full.Source企业版含ClientServer中文修正版支持Delphi 4-XE5 and C++Builder 6-XE5. D2010以上版本(D14_D19)安装必读 delphi2010以上版本(D14_D19)使用者安装时,请将res\frccD14_D19.exe更名名为frcc.exe frccD14_D19.exe是专门的delphi2010以上版本(D14_D19)编码器。其他低delphi版本,请使用frcc.exe FastReport® VCL is an add-on component that allows your application to generate reports quickly and efficiently. FastReport® provides all the tools necessary for developing reports, including a visual report designer, a reporting core, and a preview window. It can be used in Embarcadero (ex Borland and CodeGear) Delphi 4-XE5 and C++Builder 6-XE5. version 4.15 --------------- + Added Embarcadero RAD Studio XE5 support + Added Internal components for FireDac database engine + fixed bug with images in PDF export for OSX viewers + Added ability to set font charset to default in Style Editor - fixed duplex problem when printing several copies of the report - fixed problem with PNG images - fixed problem with TfrxPictureView transparent version 4.14 --------------- + Added Embarcadero RAD Studio XE4 support - [Lazarus] fixed bug with text output - [Lazarus] fixed bug with some visual controls in designer - [Lazarus] improved interface of the report preview and designer - [Lazarus] fixed bug with boolean propertyes in script code and expressions - fixed bug with endless loop in TfrxRichView - fixed bug with Unicode in TfrxMemoView appeared in previous release - improved MAPI interface in TfrxExportMail export - fixed some problems with allpication styles XE2/XE3 - improved compatibility with Fast Report FMX version 4.13 --------------- + Added Lazarus Beta support starts from Fast Report Professionnal edition. Current version allows preview, print and design report template under Windows and Linux platform (qt). + Added Embarcadero RAD Studio XE3 support - fixed compatibility with Fast Report FMX installed in the same IDE. This version can co exist with Fast Report FMX version at the same time. + published "Quality" property of TfrxPDFExport object + published "UseMAPI" property of TfrxExportMail object + published "PictureType" property to ODF export - fixed bug with expressions in RichEdit - fixed bug in multi-column reports - fixed exception in the report designer - fixed bug with URLs in Open Document Text and Open Document Spreadsheet exports - fixed format string in XLS OLE export - fixed format string in XLS BIFF8 export - fixed output of the check boxes on the highlighted lines in PDF export - fixed bug with PDF anchors - fixed bug when using two or more macroses in memo version 4.12 --------------- + added support of Embarcadero Rad Studio EX2 (x32/x64) + added export of Excel formulas in the BIFF export + added export of external URLs in the PDF export + added converter from Rave Reports ConverterRR2FR.pas + added Cross.KeepRowsTogether property + optimised merging cells in the BIFF export + added property DataOnly to exports + pictures format in all exports switched to PNG + improved number formats processing in the BIFF export + added property DataOnly to exports + added property TfrxODFExport.SingleSheet + added property TfrxSimpleTextExport.DeleteEmptyColumns + added property TfrxBIFFExport.DeleteEmptyRows + added progress bar to the BIFF export - fixed bug with frame for some barcode types - fixed wrong metafiles size in the EMF export - fixed processing of negative numbers in the OLE export - fixed bug in handling exceptions in the OLE export - fixed bug in creation of the progress bar (applicable to many exports) - fixed bug in the ODF export in strings processing - fixed bug in the OLE export in numbers formatting - fixed bug in the PDF export in rotating texts 90, 180 and 270 degrees - fixed bug in the ODF export in processing of headers and footers - fixed bug in the Text export in computing object bounds - fixed bug in the ODF export in UTF8 encoding - fixed hiding gridlines around nonempty cells in the BIFF export - fixed images bluring when exporting - fixed word wrapping in the Excel XML export version 4.11 --------------- + added BIFF8 XLS export filter + added to ODF export the Language property + [enterprise] added "scripts" folder for additional units ("uses" directive in report script) + [enterprise] added logs for scheduler (add info in scheduler.log) + [enterprise] added property "Reports" - "Scripts" in server configuration - set the path for "uses" directive in report script + [enterprise] added property "Http" - "MaxSessions" in server configuration - set the limit of maximum session threads, set 0 for unlimit + [enterprise] added property "Reports" - "MaxReports" in server configuration - set the limit of maximum report threads, set 0 for unlimit + [enterprise] added property "Logs" - "SchedulerLog" in server configuration - set the scheduler log file name + [enterprise] added property "Scheduler" - "Active" in server configuration - enable of scheduler + [enterprise] added property "Scheduler" - "Debug" in server configuration - enable writing of debug info in scheduler log + [enterprise] added property "Scheduler" - "StudioPath" in server configuration - set the path to FastReport Studio, leave blank for default - [enterprise] fixed bug with MIME types in http header (content-type) - [enterprise] fixed bug with default configuration (with missed config.xml) - [enterprise] fixed bug with error pages - fixed bug in XML export with the ShowProgress property - fixed bug in RTF export with font size in empty cells - fixed bug in ODF export with UTF8 encoding of the Creator field - fixed bug in XML export with processing special characters in strings - fixed bug in ODF export with properties table:number-columns-spanned, table:number-rows-spanned - fixed bug in ODF export with the background clNone color - fixed bug in ODF export with a style of table:covered-table-cell - fixed bug in ODF export with table:covered-table-cell duplicates - fixed bug in ODF export with excessive text:p inside table:covered-table-cell - fixed bug in ODF export with language styles - fixed bug in ODF export with spaces and tab symbols - fixed bug in ODF export with styles of number cells - fixed bug in ODF export with the background picture - fixed bug in ODF export with charspacing - fixed bug in ODF export with number formatting - fixed bug in ODF export with table-row tag - fixed bug in XLS(OLE) export with numbers formatting - fixed bug in RTF export with processing RTF fields - fixed bug with processing special symbols in HTML Export - fixed bug with UTF8 encoding in ODF export - fixed bug in PDF export with underlined, struck-out and rotated texts version 4.10 --------------- + added support of Embarcadero Rad Studio XE (Delphi EX/C++Builder EX) + added support of TeeChart 2010 packages (new series type aren't support in this release) + added a property TruncateLongTexts to the XLS OLE export that allows to disable truncating texts longer than a specified limit + added option EmbedProt which allows to disable embedding fonts into an encrypted PDF file + added TfrxDateEditControl.WeekNumbers property - fixed bug in XML and PDF exports with Korean charmap - fixed bug in the XLS XML export about striked-out texts - fixed bug about exporting an empty page via the XLS OLE export - fixed bug in the PDF export about coloring the background of pages - fixed bug in embedded designer when using break point in script - fixed bug with lost of focus in font size combo-box in designer - fixed bug with truncate of font size combo-box in Windows Vista/7 in designer (lost of vertical scroll bar) - fixed bug when lost file name in inherited report - fixed bug in multi-page report with EndlessHeight/EndlessWidth - fixed bug wit TfrxHeader.ReprintOnNewpage and KeepTogether - fixed bug in multi-column report with child bands - improved split mechanism (added TfrxStretcheable.HasNextDataPart for complicated data like RTF tables) - improved crosstab speed when using repeat band with crosstab object version 4.9 --------------- + added outline to PDF export + added anchors to PDF export - fixed bug with embedded TTC fonts in PDF export + added an ability to create multiimage TIFF files + added export headers/footers in ODF export + added ability to print/export transparent pictures (properties TfrxPictureView.Transparent and TfrxPictureView.TransparentColor) (PDF export isn't supported) + added new "split to sheet" modes for TfrxXMLExport + added support of /PAGE tag in TfrxRichView, engine automatically break report pages when find /PAGE tag + added ability to hide Null values in TfrxChartView (TfrxChartView.IgnoreNulls = True) + added ability to set any custom page order for printing (i.e. 3,2,1,5,4 ) + [enterprise] added variables "AUTHLOGIN" and "AUTHGROUP" inside the any report + [enterprise] now any report file can be matched with any (one and more) group, these reports are accessible only in matched groups + [enterprise] now you can set-up cache delays for each report file (reports.xml) + [enterprise] added new properties editor for reports in Configuration utility (see Reports tab) + [enterprise] added property "Xml" - "SplitType" in server configuration - allow to select split on pages type between none/pages/printonprev/rowscount + [enterprise] added property "Xml" - "SplitRowsCount" in server configuration - sets the count of rows for "rowscount" split type + [enterprise] added property "Xml" - "Extension" in server configuration - allow select between ".xml" and ".xls" extension for output file + [enterprise] added property "Html" - "URLTarget" in server configuration - allow select the target attribute for report URLs + [enterprise] added property "ReportsFile" - path to file with reports to groups associations and cache delays + [enterprise] added property "ReportsListRenewTimeout" in server configuration + [enterprise] added property "ConfigRenewTimeout" in server configuration + [enterprise] added property "MimeType" for each output format in server configuration + [enterprise] added property "BrowserPrint" in server configuration - allow printing by browser, added new template nav_print_browser.html + [enterprise] added dynamic file name generation of resulting formats (report_name_date_time) * [enterprise] SERVER_REPORTS_LIST and SERVER_REPORTS_HTML variables (list of available reports) depend from user group (for internal authentification) + added drawing shapes in PDF export (not bitmap) + added rotated text in PDF export (not bitmap) + added EngineOptions.IgnoreDevByZero property allow to ignore division by zero exception in expressions + added properties TfrxDBLookupComboBox.DropDownWidth, TfrxDBLookupComboBox.DropDownRows + added event TfrxCustomExportFilter.OnBeginExport + added ability to decrease font size in barcode object + added ability to inseret FNC1 to "code 128" barcode + added event TfrxPreview.OnMouseDown + added support of new unicode-PDF export in D4-D6 and BCB4-BCB6 * improved AddFrom method - anchor coping - fixed bug with WordWrap in PDF export - fixed bug with underlines in PDF export - fixed bug with rounded rectangles in PDF export - fixed CSV export to fit to the RFC 4180 specification - fixed bug with strikeout text in PDF export - fixed bug with incorrect export of TfrxRichView object in RTF format (wrong line spacing) - [enterprise] added critical section in TfrxServerLog.Write - fixed bug with setting up of the Protection Flags in the PDF export dialog window - fixed bug in PDF export (file structure) - fixed bug with pictures in Open Office Writer (odt) export - [enterprise] fixed bug with TfrxReportServer component in Delphi 2010 - fixed minor errors in Embarcedero RAD Studio 2010 - fixed bug with endless loop with using vertical bands together with page header and header with ReprintOnNewPage - fixed bug when using "Keeping" and Cross tables (incorrect cross transfer) - fixed bug with [CopyName#] macros when use "Join small pages" print mode - fixed bug when try to split page with endless height to several pages (NewPage, StartNewPage) - fixed bug with empty line TfrxRichView when adding text via expression - fixed bug when Footer prints even if main band is invisible (FooterAfterEach = True) - fixed resetting of Page variable in double-pass report with TfrxCrossView - fixed bug with loosing of aligning when split TfrxRichView - fixed buzz in reports with TfrxRichView when using RTF 4.1 version 4.8 --------------- + added support of Embarcadero Rad Studio 2010 (Delphi/C++Builder) + added TfrxDBDataset.BCDToCurrency property + added TfrxReportOptions.HiddenPassword property to set password silently from code + added TfrxADOConnection.OnAfterDisconnect event + added TfrxDesigner.MemoParentFont property + added new TfrxDesignerRestriction: drDontEditReportScript and drDontEditInternalDatasets + adedd checksum calculating for 2 5 interleaved barcode + added TfrxGroupHeader.ShowChildIfDrillDown property + added TfrxMailExport.OnSendMail event + added RTF 4.1 support for TfrxRichText object + [enterprise] added Windows Authentification mode + added confirmation reading for TfrxMailExport + added TimeOut field to TfrxMailExport form + added ability to use keeping(KeepTogether/KeepChild/KeepHeader) in multi-column report + added ability to split big bands(biggest than page height) by default * [enterprise] improved CGI for IIS/Apache server * changed PDF export (D7 and upper): added full unicode support, improved performance, decreased memory requirements old PDF export engine saved in file frxExportPDF_old.pas - changed inheritance mechanism, correct inherits of linked objects (fixups) - fixed bug with Mirror Mrgins in RTF, HTML, XLS, XML, OpenOffice exports - fixed bug when cross tab cut the text in corner, when corner height greater than column height - [fs] improved script compilation - improved WatchForm TListBox changet to TCheckListBox - improved AddFrom method - copy outline - Improved functional of vertical bands, shows memos placed on H-band which doesn't across VBand, also calculate expression inside it and call events (like in FR2) - Improved unsorted mode in crosstab(join same columns correctly) - Improved converter from Report Builder - Improved TfrxDesigner.OnInsertObject, should call when drag&drop field from data tree - improved DrillDownd mechanism, should work correct with master-detail-subtetail nesting - fixed bug with DownThenAcross in Cross Tab - fixed several bugs under CodeGear RAD Studio (Delphi/C++Builder) 2009 - fixed bug with emf in ODT export - fixed bug with outline when build several composite reports in double pass mode - fixed bug when group doesn't fit on the whole page - fixed "Page" and "Line" variables inside vertical bands - fixed bug with using KeepHeader in some cases - fixed bug with displacement of subreport when use PrintOnParent property in some cases - fixed small memory leak in subreports - fixed problem with PageFooter and ReportSymmary when use PrintOnPreviousPage property - fixed bug when designer shows commented functions in object inspector - fixed bug when designer place function in commented text block - fixed bug when Engine try to split non-stretcheable view and gone to endless loop - fixed bug with HTML tags in memo when use shot text and WordWrap - [enterprise] fixed bug with variables lost on refresh/export - fixed bug whih PDF,ODT export in Delphi4 and CBuilder4 - fixed bug with some codepage which use two bytes for special symbols (Japanese ans Chinese codepages) - fixed bug when engine delete first space from text in split Memo - fixed bug in multi-column page when band overlap stretched PageHeader - fixed bug with using ReprintOnNewPage version 4.7 --------------- + CodeGear RAD Studio (Delphi/C++Builder) 2009 support + [enterprise] enchanced error description in logs + added properties TfrxHTMLExport.HTMLDocumentBegin: TStrings, TfrxHTMLExport.HTMLDocumentBody: TStrings, TfrxHTMLExport.HTMLDocumentEnd: TStrings + improved RTF export (with line spacing, vertical gap etc) + added support of Enhanced Metafile (EMF) images in Rich Text (RTF), Open Office (ODS), Excel (XLS) exports + added OnAfterScriptCompile event + added onLoadRecentFile Event + added C++ Builder demos + added hot-key Ctrl + mouseWheel - Change scale in designer + added TfrxMemoView.AnsiText property - fixed bug in RTF export with EMF pictures in OpenOffice Writer - fixed some multi-thread isuues in engine, PDF, ODF exports - [enterprise] fixed integrated template of report navigator - [enterprise] fixed bug with export in Internet Explorer browser - fixed bug with font size of dot-matix reports in Excel and XML exports - fixed bug in e-mail export with many addresses - fixed bug in XLS export (with fast export unchecked and image object is null) - [enterprise] fixed bug in TfrxReportServer.OnGetVariables event - fixed bug in Calcl function - fixed memory leak in Cross editor - fixed progress bar and find dialog bug in DualView - fixed bug in PostNET and ean13 barcodes - fixed bug with TruncOutboundText in Dot Matrix report - fixed bugs with break points in syntaxis memo - improved BeforeConnect event in ADO - fixed bug in inhehited report with internal dataset - fixed bug in TfrxPanelControl with background color(Delphi 2005 and above) version 4.6 --------------- + added & , < , > to XML reader + added tag, the text concluded in tag is not broken by WordWrap, it move entirely + added ability to move band without objects (Alt + Move) + added ability to output pages in the preview from right to left ("many pages" mode), for RTL languages(PreviewOptions.RTLPreview) + added ability to storing picture cache in "temp" file (PreviewOptions.PictureCacheInFile) + added EngineOptions.UseGlobalDataSetList (added for multi-thread applications) - set it to False if you don't want use Global DataSet list(use Report.EnabledDataSet.Add() to add dataset in local list) + added new property Hint for all printed objects, hints at the dialog objects now shows in StatusBar + added new property TfrxDBLookupComboBox.AutoOpenDataSet (automatically opens the attached dataset after onActivate event) + added new property TfrxReportPage.PageCount like TfrxDataBand.RowCount + added new property WordWrap for dialog buttons (Delphi 7 and above). + added sort by name to data tree + added TfrxDesigner.TemplatesExt property + added TfrxStyles class in script rtti + changes in the Chart editor: ability to change the name of the series, ability to move created series, other small changes + [enterprise] added configurations values refresh in run-time + [enterprise] added new demo \Demos\ClientServer\ISAPI + [enterprise] added output to server printers from user browser (see config.xml "AllowPrint", set to "no" by default), note: experimental feature + [enterprise] added reports list refresh in run-time + [enterprise] added templates feature + [enterprise] improved speed and stability + [fs] added TfsScript.IncludePath property + [fs] added TfsScript.UseClassLateBinding property + [fs] fixed type casting from variant(string) to integer/float - changes in report inherit: FR get relative path from current loaded report(old reports based on application path works too) - corrected module for converting reports from Report Builder - fixed bug in CrossTab when set charset different from DEFAULT_CHARSET - fixed bug in RTF export with some TfrxRichView objects - fixed bug when print on landscape orientation with custom paper size - fixed bug when use network path for parent report - fixed bug with Band.Allowslit = True and ColumnFooter - fixed bug with drawing subreport on stretched band - fixed bug with embedded fonts in PDF export - fixed bug with long ReportTitle + Header + MaterData.KeepHeader = true - fixed bug with minimizing of Modal designer in BDS2005 and above - fixed bug with paths in HTML export - fixed bug with RTL in PDF export - fixed bug with SubReport in multi column page - fixed bug with Subreport.PrintOnParent = true in inherited report - fixed bug with SYMBOL_CHARSET in PDF export - fixed bug with the addition of datasets by inheritance report - fixed bug with width calculation when use HTML tags in memo - fixed compatibility with WideStrings module in BDS2006/2007 - fixed flicking in preview when use OnClickObject event - fixed free space calculation when use PrintOnPreviousPage - fixed preview bug with winXP themes and in last update - fixed subreports inherit - Thumbnail and Outline shows at right side for RTL languages - [fs] fixed bug with late binding version 4.5 --------------- + added ConverterRB2FR.pas unit for converting reports from Report Builder to Fast Report + added ConverterQR2FR.pas unit for converting reports from QuickReport to FastReport + added support of multiple attachments in e-mail export (html with images as example) + added support of unicode (UTF-8) in e-mail export + added ability to change templates path in designer + added OnReportPrint script event + added PNG support in all version (start from Basic) + added TfrxDMPMemoView.TruncOutboundText property - truncate outbound text in matrix report when WordWrap=false + added new frames styles fsAltDot and fsSquare + added new event OnPreviewDblClick in all TfrxView components + added ability to call dialogs event after report run when set DestroyForms = false + added ability to change AllowExpressions and HideZeros properties in cross Cells (default=false) + added IgnoreDupParams property to DB components + added auto open dataset in TfrxDBLookupComboBox + added new property TfrxADOQuery.LockType + added define DB_CAT (frx.inc) for grouping DB components + added TfrxPictureView.HightQuality property(draw picture in preview with hight quality, but slow down drawing procedure) + [FRViewer] added comandline options "/print filename" and "/silent_print filename" + added unicode input support in RichEditor + added new define HOOK_WNDPROC_FOR_UNICODE (frx.inc) - set hook on GetMessage function for unicode input support in D4-D7/BCB4-BCB6 + added ability chose path to FIB packages in "Recompile Wizard" + added new function TfrxPreview.GetTopPosition, return a position on current preview page + added new hot-keys to Code Editor - Ctrl+Del delete the word before cursor, Ctrl+BackSpace delete the word after cursor(as in Delhi IDE) + added "MDI Designer" example - all language resources moved to UTF8, XML - fixed bug with html tags [sup] and [sub] - fixed width calculation in TfrxMemoView when use HTML tags - fixed bug with suppressRepeated in Vertical bands - fixed bug when designer not restore scrollbars position after undo/redo - fixed visual bug in toolbars when use Windows Vista + XPManifest + Delphi 2006 - fixed bug in CalcHeight when use negative LineSpace - fixed bug in frx2xto30 when import query/table components, added import for TfrDBLookupControl component - fixed bug with Cross and TfrxHeader.ReprintOnNewPage = true - fixed converting from unicode in TfrxMemoView when use non default charset - [fs] fixed bug with "in" operator - fixed bug with aggregate function SUM - fixed bug when use unicode string with [TotalPages#] in TfrxMemoView - fixed bug with TSQLTimeStampField field type - fixed designer dock-panels("Object Inspector", "Report Tree", "Data Tree") when use designer as MDI or use several non-modal designer windows - fixed bug with hide/show dock-panels("Object Inspector", "Report Tree", "Data Tree"), now it restore size after hiding - fixed bug in XML/XLS export - wrong encode numbers in memo after CR/LF - fiexd bug in RTF export - fixed bug with undo/redo commands in previewPages designer - fixed bug with SuppressRepeated when use KeepTogether in group - fixed bug with SuppressRepeated on new page all events fired twice(use Engine.SecondScriptcall to determinate it) version 4.4 --------------- + added support for CodeGear RAD Studio 2007 + improved speed of PDF, HTML, RTF, XML, ODS, ODT exports + added TfrxReportPage.BackPictureVisible, BackPicturePrintable properties + added rtti for the TfrxCrossView.CellFunctions property + added properties TfrxPDFExport.Keywords, TfrxPDFExport.Producer, TfrxPDFExport.HideToolbar, TfrxPDFExport.HideMenubar, TfrxPDFExport.HideWindowUI, TfrxPDFExport.FitWindow, TfrxPDFExport.CenterWindow, TfrxPDFExport.PrintScaling + added ability recompile frxFIB packages in "recompile wizard" + added ability to set color property for all teechart series which support it + added, setting frame style for each frame line in style editor + added TfrxPreview.Locked property and TfrxPreview.DblClick event + added 'invalid password' exception when load report without crypt + added new parameter to InheritFromTemplate (by default = imDefault) imDefault - show Error dialog, imDelete - delete duplicates, imRename - rename duplicates + added property TfrxRTFExport.AutoSize (default is "False") for set vertical autosize in table cells * redesigned dialog window of PDF export * improved WYSIWYG in PDF export - fixed bug, the PageFooter band overlap the ReportSummary band when use EndlessHeight - fixed bug with lage paper height in preview - fixed bug with outline and encryption in PDF export - fixed bug with solid arrows in PDF export - fixed bug when print TfrxHeader on a new page if ReprintOnNewPage = true and KeepFooter = True - fixed bug when used AllowSplit and TfrxGroupHeader.KeepTogether - fixed page numbers when print dotMatrix report without dialog - fixed bug with EndlessHeight in multi-columns report - fixed font dialog in rich editor - [fs] fixed bug when create TWideStrings in script code - fixed bug with dialog form when set TfrxButtonControl.Default property to True - fixed twice duplicate name error in PreviewPages designer when copy - past object - fixed bug with Preview.Clear and ZmWholePage mode - fixed bug with using "outline" together "embedded fonts" options in PDF export - fixed multi-thread bug in PDF export - fixed bug with solid fill of transparent rectangle shape in PDF export - fixed bug with export OEM_CODEPAGE in RTF, Excel exports - fixed bug with vertical size of single page in RTF export - fixed bug with vertical arrows in PDF export - fixed memory leak with inherited reports version 4.3 --------------- + added support for C++Builder 2007 + added encryption in PDF export + added TeeChart Pro 8 support + added support of OEM code page in PDF export + added TfrxReport.CaseSensitiveExpressions property + added "OverwritePrompt" property in all export components + improved RTF export (WYSIWYG) + added support of thai and vietnamese charsets in PDF export + added support of arrows in PDF export * at inheritance of the report the script from the report of an ancestor is added to the current report (as comments) * some changes in PDF export core - fixed bug with number formats in Open Document Spreadsheet export - fixed bug when input text in number property(Object Inspector) and close Designer(without apply changes) - fixed bug in TfrxDBDataset with reCurrent - fixed bug with memory leak in export of empty outline in PDF format - line# fix (bug with subreports) - fixed bug with edit prepared report with rich object - fixed bug with shadows in PDF export - fixed bug with arrows in designer - fixed bug with margins in HTML, RTF, XLS, XML exports - fixed bug with arrows in exports - fixed bug with printers enumeration in designer (list index of bound) - fixed papersize bug in inherited reports version 4.2 --------------- + added support for CodeGear Delphi 2007 + added export of html tags in RTF format + improved split of the rich object + improved split of the memo object + added TfrxReportPage.ResetPageNumbers property + added support of underlines property in PDF export * export of the memos formatted as fkNumeric to float in ODS export - fixed bug keeptogether with aggregates - fixed bug with double-line draw in RTF export - fix multi-thread problem in PDF export - fixed bug with the shading of the paragraph in RTF export when external rich-text was inserted - fixed bug with unicode in xml/xls export - fixed bug in the crop of page in BMP, TIFF, Jpeg, Gif - "scale" printmode fixed - group & userdataset bugfix - fixed cross-tab pagination error - fixed bug with round brackets in PDF export - fixed bug with gray to black colors in RTF export - fixed outline with page.endlessheight - fixed SuppressRepeated & new page - fixed bug with long time export in text format - fixed bug with page range and outline in PDF export - fixed undo in code window - fixed error when call DesignReport twice - fixed unicode in the cross object - fixed designreportinpanel with dialog forms - fixed paste of DMPCommand object - fixed bug with the export of null images - fixed code completion bug - fixed column footer & report summary problem version 4.1 --------------- + added ability to show designer inside panel (TfrxReport.DesignReportInPanel method). See new demo Demos\EmbedDesigner + added TeeChart7 Std support + [server] added "User" parameter in TfrxReportServer.OnGetReport, TfrxReportServer.OnGetVariables and TfrxReportServer.OnAfterBuildReport events + added Cross.KeepTogether property + added TfrxReport.PreviewOptions.PagesInCache property - barcode fix (export w/o preview bug) - fixed bug in preview (AV with zoommode = zmWholePage) - fixed bug with outline + drilldown - fixed datasets in inherited report - [install] fixed bug with library path set up in BDS/Turbo C++ Builder installation - fixed pagefooter position if page.EndlessWidth is true - fixed shift bug - fixed design-time inheritance (folder issues) - fixed chm help file path - fixed embedded fonts in PDF - fixed preview buttons - fixed bug with syntax highlight - fixed bug with print scale mode - fixed bug with control.Hint - fixed edit preview page - fixed memory leak in cross-tab version 4.0 initial release --------------------- Report Designer: - new XP-style interface - the "Data" tab with all report datasets - ability to draw diagrams in the "Data" tab - code completion (Ctrl+Space) - breakpoints - watches - report templates - local guidelines (appears when you move or resize an object) - ability to work in non-modal mode, mdi child mode Report Preview: - thumbnails Print: - split a big page to several small pages - print several small pages on one big - print a page on a specified sheet (with scale) - duplex handling from print dialogue - print copy name on each printed copy (for example, "First copy", "Second copy") Report Core: - "endless page" mode - images handling, increased speed - the "Reset page numbers" mode for groups - reports crypting (Rijndael algorithm) - report inheritance (both file-based and dfm-based) - drill-down groups - frxGlobalVariables object - "cross-tab" object enhancements: - improved cells appearance - cross elements visible in the designer - fill corner (ShowCorner property) - side-by-side crosstabs (NextCross property) - join cells with the same value (JoinEqualCells property) - join the same string values in a cell (AllowDuplicates property) - ability to put an external object inside cross-tab - AddWidth, AddHeight properties to increase width&height of the cell - AutoSize property, ability to resize cells manually - line object can have arrows - added TfrxPictureView.FileLink property (can contain variable or a file name) - separate settings for each frame line (properties Frame.LeftLine, TopLine, RightLine, BottomLine can be set in the object inspector) - PNG images support (uncomment {$DEFINE PNG} in the frx.inc file) - Open Document Format for Office Applications (OASIS) exports, spreadsheet (ods) and text (odt) Enterprise components: - Users/Groups security support (see a demo application Demos\ClientServer\UserManager) - Templates support - Dynamically refresh of configuration, users/groups D2010以上版本(D14_D19)安装必读 delphi2010以上版本(D14_D19)使用者安装时,请将res\frccD14_D19.exe更名名为frcc.exe frccD14_D19.exe是专门的delphi2010以上版本(D14_D19)编码器。其他低delphi版本,请使用frcc.exe
一、Qt Creator 的安装和hello world 程序的编写(原创) 1.首先到Qt 的官方网站上下载Qt Creator,这里我们下载windows 版的。 下载地址:http://qt.nokia.com/downloads 如下图我们下载:Download Qt SDK for Windows* (178Mb) 下载完成后,直接安装即可,安装过程中按默认设置即可。 2.运行Qt Creator,首先弹出的是欢迎界面,这里可以打开其自带的各种演示 程序。 3.我们用File->New 菜单来新建工程。 4.这里我们选择Qt4 Gui Application。 5.下面输入工程名和要保存到的文件夹路径。我们这里的工程名为helloworld。 6.这时软件自动添加基本的头文件,因为这个程序我们不需要其他的功能,所以 直接点击Next。 7.我们将base class 选为QDialog 对话框类。然后点击Next。 8.点击Finish,完成工程的建立。 9.我们可以看见工程中的所有文件都出现在列表中了。我们可以直接按下下面的 绿色的run 按钮或者按下Ctrl+R 快捷键运行程序。 10.程序运行会出现空白的对话框,如下图。 11.我们双击文件列表的dialog.ui 文件,便出现了下面所示的图形界面编辑界 面。 12.我们在右边的器件栏里找到Label 标签器件 13.按着鼠标左键将其拖到设计窗口上,如下图。 14.我们双击它,并将其内容改为helloworld。 15.我们在右下角的属性栏里将字体大小由9 改为15。 16.我们拖动标签一角的蓝点,将全部文字显示出来。 17.再次按下运行按钮,便会出现helloworld。 到这里helloworld 程序便完成了。 Qt Creator 编译的程序,在其工程文件夹下会有一个debug 文件夹,其中有程序的.exe 可执行文件。但Qt Creator 默认是用动态链接的, 就是可执行程序在运行时需要相应的.dll 文件。我们点击生成的.exe 文件,首 先可能显示“没有找到mingwm10.dll,因此这个应用程序未能启动。重新安装 应用程序可能会修复此问题。”表示缺少mingwm10.dll 文件。 解决这个问题我们可以将相应的.dll 文件放到系统 中。在Qt Creator 的安装目录的qt 文件下的bin 文件夹下(我安装在了D 盘, 所以路径是D:\Qt\2009.04\qt\bin),可以找到所有的相关.dll 文件。在这里 找到mingwm10.dll 文件,将其复制到C:\WINDOWS\system 文件夹下,即可。下 面再提示缺少什么dll 文件,都像这样解决就可以了。 二、Qt Creator 编写多窗口程序(原创) 实现功能: 程序开始出现一个对话框,按下按钮后便能进入主窗口,如果直 接关闭这个对话框,便不能进入主窗口,整个程序也将退出。当进入主窗口后, 我们按下按钮,会弹出一个对话框,无论如何关闭这个对话框,都会回到主窗口。 实现原理: 程序里我们先建立一个主工程,作为主界面,然后再建立一个对 话框类,将其加入工程中,然后在程序中调用自己新建的对话框类来实现多窗口。 实现过程: 1.首先新建Qt4 Gui Application 工程,工程名为nGui,Base class 选为QWidget。 建立好后工程文件列表如下图。 2.新建对话框类,如下图,在新建中,选择Qt Designer Form Class。 3.选择Dialog without Buttons。 4.类名设为myDlg。 5.点击Finish 完成。注意这里已经默认将其加入到了我们刚建的工程中了。 6.如下图,在mydlg.ui 中拖入一个Push Button,将其上的文本改为“进入主 窗口”,在其属性窗口中将其objectName 改为enterBtn,在下面的Signals and slots editor 中进行信号和槽的关联,其中,Sender 设为enterBtn,Signal 设为clicked(),Receive 设为myDlg,Slot 设为accept()。这样就实现了单击 这个按钮使这个对话框关闭并发出Accepted 信号的功能。下面我们将利用这个 信号。 7.修改主函数main.cpp,如下: #include #include "widget.h" #include "mydlg.h" //加入头文件 int main(int argc, char *argv[]) { QApplication a(argc, argv); Widget w; myDlg my1; //建立自己新建的类的对象my1 if(my1.exec()==QDialog::Accepted) //利用Accepted 信号判 断enterBtn 是否被按下 { w.show(); //如果被按下,显示主窗口 return a.exec(); //程序一直执行,直到主窗口 关闭 } else return 0; //如果没被按下,则不会进入主窗口,整个程 序结束运行 } 主函数必须这么写,才能完成所要的功能。 如果主函数写成下面这样: #include #include "widget.h" #include "mydlg.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); myDlg my1; if(my1.exec()==QDialog::Accepted) { Widget w; w.show(); } return a.exec(); } 这样,因为w 是在if 语句里定义的,所以当if 语句执行完后它就无效了。这样 导致的后果就是,按下enterBtn 后,主界面窗口一闪就没了。如果此时对程序 改动了,再次点击运行时,就会出现error: collect2: ld returned 1 exit status 的错误。这是因为虽然主窗口没有显示,但它只是隐藏了,程序并没有 结束,而是在后台运行。所以这时改动程序,再运行时便会出错。你可以按下调 试栏上面的红色Stop 停止按钮来停止程序运行。你也可以在windows 任务管理 器的进程中将该进程结束,而后再次运行就没问题了,当然先关闭Qt Creator, 而后再重新打开,这样也能解决问题。 如果把程序改为这样: #include #include "widget.h" #include "mydlg.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); myDlg my1; Widget w; if(my1.exec()==QDialog::Accepted) { w.show(); } return a.exec(); } 这样虽然解决了上面主窗口一闪而过的问题,但是,如果在my1 对话框出现的时 候不点enterBtn,而是直接关闭对话框,那么此时整个程序应该结束执行,但 是事实是这样的吗?如果你此时对程序进行了改动,再次按下run 按钮,你会发 现又出现了error: collect2: ld returned 1 exit status 的错误,这说明程 序并没有结束,我们可以打开windows 任务管理器,可以看到我们的程序仍在执 行。 因为return a.exec();一句表示只要主窗口界面不退出,那么程 序就会一直执行。所以只有用第一种方法,将该语句也放到if 语句中,而在else 语句中用else return 0; ,这样如果enterBtn 没有被按下,那么程序就会结 束执行了。 到这里,我们就实现了一个界面结束执行,然后弹出另一个 界面的程序。下面我们在主窗口上加一个按钮,按下该按钮,弹出一个对话框, 但这个对话框关闭,不会使主窗口关闭。 8.如下图,在主窗口加入按钮,显示文本为“弹出一个对话框”,在其上点击鼠 标右键,在弹出的菜单中选择go to slot。 9.我们选择单击事件clicked()。 10.我们在弹出的槽函数中添加一句: my2.show(); my2 为我们新建对话框类的另一个对象,但是my2 我们还没有定义,所以 在widget.h 文件中添加相应代码,如下,先加入头文件,再加入my2 的定义语 句,这里我们将其放到private 里,因为一般的函数都放在public 里,而变量 都放在private 里。 #ifndef WIDGET_H #define WIDGET_H #include #include "mydlg.h" //包含头文件 namespace Ui { class Widget; } class Widget : public QWidget { Q_OBJECT public: Widget(QWidget *parent = 0); ~Widget(); private: Ui::Widget *ui; myDlg my2; //对my2 进行定义 private slots: void on_pushButton_clicked(); }; #endif // WIDGET_H 到这里,再运行程序,便能完成我们实验要求的功能了。整个程序里,我们用两 种方法实现了信号和槽函数的关联,第一个按钮我们直接在设计器中实现其关 联;第二个按钮我们自己写了槽函数语句,其实图形的设计与直接写代码效果是 一样的。 这个程序里我们实现了两类窗口打开的方式,一个是自身消失而 后打开另一个窗口,一个是打开另一个窗口而自身不消失。可以看到他们实现的 方法是不同的。 三、Qt Creator 登录对话框(原创) 实现功能: 在弹出对话框中填写用户名和密码,按下登录按钮,如果用户名和密码均正确则 进入主窗口,如果有错则弹出警告对话框。 实现原理: 通过上节的多窗口原理实现由登录对话框进入主窗口,而用户名和密码可以用 if 语句进行判断。 实现过程: 1.先新建Qt4 Gui Application 工程,工程名为mainWidget,选用QWidget 作 为Base class,这样便建立了主窗口。文件列表如下: 2.然后新建一个Qt Designer Form Class 类,类名为loginDlg,选用Dialog without Buttons,将其加入上面的工程中。文件列表如下: 3.在logindlg.ui 中设计下面的界面:行输入框为Line Edit。其中用户名后面 的输入框在属性中设置其object Name 为usrLineEdit,密码后面的输入框为 pwdLineEdit,登录按钮为loginBtn,退出按钮为exitBtn。 4.将exitBtn 的单击后效果设为退出程序,关联如下: 5.右击登录按钮选择go to slot,再选择clicked(),然后进入其单击事件的槽 函数,写入一句 void loginDlg::on_loginBtn_clicked() { accept(); } 6.改写main.cpp: #include #include "widget.h" #include "logindlg.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); Widget w; loginDlg login; if(login.exec()==QDialog::Accepted) { w.show(); return a.exec(); } else return 0; } 7.这时执行程序,可实现按下登录按钮进入主窗口,按下退出按钮退出程序。 8.添加用户名密码判断功能。将登陆按钮的槽函数改为: void loginDlg::on_loginBtn_clicked() { if(m_ui->usrLineEdit->text()==tr("qt")&&m_ui->pwdLineEdit->text()==tr ("123456")) //判断用户名和密码是否正确 accept(); else{ QMessageBox::warning(this,tr("Warning"),tr("user name or password error!"),QMessageBox::Yes); //如果不正确,弹出警告对话框 } } 并在logindlg.cpp 中加入#include 的头文件。如果不加这个头文件, QMessageBox 类不可用。 9.这时再执行程序,输入用户名为qt,密码为123456,按登录按钮便能进入主 窗口了,如果输入错了,就会弹出警告对话框。 如果输入错误,便会弹出警告提示框: 10.在logindlg.cpp 的loginDlg 类构造函数里,添上初始化语句,使密码显示 为小黑点。 loginDlg::loginDlg(QWidget *parent) : QDialog(parent), m_ui(new Ui::loginDlg) { m_ui->setupUi(this); m_ui->pwdLineEdit->setEchoMode(QLineEdit::Password); } 效果如下: 11.如果输入如下图中的用户名,在用户名前不小心加上了一些空格,结果程序 按错误的用户名对待了。 我们可以更改if 判断语句,使这样的输入也算正确。 void loginDlg::on_loginBtn_clicked() { if(m_ui->usrLineEdit->text().trimmed()==tr("qt")&&m_ui->pwdLineEdit-> text()==tr("123456")) accept(); else{ QMessageBox::warning(this,tr("Warning"),tr("user name or password error!"),QMessageBox::Yes); } } 加入的这个函数的作用就是移除字符串开头和结尾的空白字符。 12.最后,如果输入错误了,重新回到登录对话框时,我们希望可以使用户名和 密码框清空并且光标自动跳转到用户名输入框,最终的登录按钮的单击事件的槽 函数如下: void loginDlg::on_loginBtn_clicked() { if(m_ui->usrLineEdit->text().trimmed()==tr("qt")&&m_ui->pwdLineEdit-> text()==tr("123456")) //判断用户名和密码是否正确 accept(); else{ QMessageBox::warning(this,tr("Warning"),tr("user name or password error!"),QMessageBox::Yes); //如果不正确,弹出警告对话框 m_ui->usrLineEdit->clear();//清空用户名输入框 m_ui->pwdLineEdit->clear();//清空密码输入框 m_ui->usrLineEdit->setFocus();//将光标转到用户名输入框 } } 四、Qt Creator 添加菜单图标(原创) 在下面的几节,我们讲述Qt 的MainWindow 主窗口部件。这一节只讲述怎样在其 上的菜单栏里添加菜单和图标。 1.新建Qt4 Gui Application 工程,将工程命名为MainWindow,其他选项默认 即可。 生成的窗口界面如下图。其中最上面的为菜单栏。 2.我们在Type Here 那里双击,并输入“文件(&F)”,这样便可将其文件菜单的 快捷键设为Alt+F。(注意括号最好用英文半角输入,这样看着美观) 3.输入完按下Enter 键确认即可,然后在子菜单中加入“新建(&N)”,确定后, 效果如下图。 4.我们在下面的动作编辑窗口可以看到新加的“新建”菜单。 5.双击这一条,可打开它的编辑对话框。我们看到Icon 项,这里可以更改“新 建”菜单的图标。 6.我们点击后面的...号,进入资源选择器,但现在这里面是空的。所以下面我 们需要给该工程添加外部资源。 7.添加资源有两种方法。一种是直接添加系统提供的资源文件,然后选择所需图 标。另一种是自己写资源文件。我们主要介绍第一种。新建Qt Resources file, 将它命名为menu。其他默认。 8.添加完后如下图。可以看到添加的文件为menu.qrc。 9.我们最好先在工程文件夹里新建一个文件夹,如images,然后将需要的图标 文件放到其中。 10.在Qt Creator 的menu.qrc 文件中,我们点击Add 下拉框,选择Add Prefix。 我们可以将生成的/new/prefix 前缀改为其他名字,如/File。 11.然后再选择Add 下拉框,选择Add Files。再弹出的对话框中,我们到新建 的images 文件夹下,将里面的图标文件全部添加过来。 12.添加完成后,我们在Qt Creator 的File 菜单里选择Save All 选项,保存所 做的更改。 13.这时再打开资源选择器,可以看到我们的图标都在这里了。(注意:如果不显 示,可以按一下上面的Reload 按钮) 14.我们将new.png 作为“新建”菜单的图标,然后点击Shortcut,并按下 Crtl+N,便能将Crtl+N 作为“新建”菜单的快捷键。 15.这时打开文件菜单,可以看到“新建”菜单已经有图标了。 运行程序后效果如下。 16.我们在工程文件夹下查看建立的menu.qrc 文件,可以用写字板将它打开。 其具体内容如下。 附:第二种添加资源文件的方法。 1.首先右击工程文件夹,在弹出的菜单中选择Add New,添加新文件。也可以用 File 中的添加新文件。 2.我们选择文本文件。 3.将文件名设置为menu.qrc。 4.添加好文件后将其内容修改如下。可以看到就是用第一种方法生成的 menu.qrc 文件的内容。 5.保存文件后,在资源管理器中可以看到添加的图标文件。 五、Qt Creator 布局管理器的使用(原创) 上篇讲解了如何在Qt Creator 中添加资源文件,并且为菜单添加了图标。这次 我们先对那个界面进行一些完善,然后讲解一些布局管理器的知识。 首先对菜单进行完善。 1.我们在上一次的基础上再加入一些常用菜单。 “文件”的子菜单如下图。中间的分割线可以点击Add Separator 添加。 “编辑”子菜单的内容如下。 “帮助”子菜单的内容如下。 2.我们在动作编辑器中对各个菜单的属性进行设置。 如下图。 3.我们拖动“新建”菜单的图标,将其放到工具栏里。 拖动“新建”菜单的图标。 将其放到菜单栏下面的工具栏里。 4.我们再添加其他几个图标。使用Append Separator 可以添加分割线。 5.最终效果如下。如果需要删除图标,可以在图标上点击右键选择Remove action 即可。 下面简述一下布局管理器。 (这里主要以垂直布局管理器进行讲解,其他类型管理器用法与之相同,其效 果可自己验证。) 1.在左边的器件栏里拖入三个PushButton 和一个Vertical Layout(垂直布局 管理器)到中心面板。如下图。 2.将这三个按钮放入垂直布局管理器,效果如下。可以看到按钮垂直方向排列, 并且宽度可以改变,但高度没有改变。 3.我们将布局管理器整体选中,按下上面工具栏的Break Layout 按钮,便可取 消布局管理器。(我们当然也可以先将按钮移出,再按下Delete 键将布局管理 器删除。) 4.下面我们改用分裂器部件(QSplitter)。 先将三个按钮同时选中,再按下上面工具栏的Lay Out Vertically in Splitter (垂直分裂器)。 效果如下图。可以看到按钮的大小可以随之改动。这也就是分裂器和布局管理器 的分别。 5.其实布局管理器不但能控制器件的布局,还有个很重要的用途是,它能使器件 的大小随着窗口大小的改变而改变。 我们先在主窗口的中心拖入一个文本编辑器Text Edit。 这时直接运行程序,效果如下。可以看到它的大小和位置不会随着窗口改变。 下面我们选中主窗口部件,然后在空白处点击鼠标右键,选择Layout->Lay Out in a Grid,使整个主窗口的中心区处于网格布局管理器中。 可以看到,这时文本编辑器已经占据了整个主窗口的中心区。 运行一下程序,可以看到无论怎样拉伸窗口,文本编辑框的大小都会随之改变。 我们在这里一共讲述了三种使用布局管理器的方法,一种是去器件栏添加,一 种是用工具栏的快捷图标,还有一种是使用鼠标右键的选项。 程序中用到的图标是我从Ubuntu 中复制的,可以到 http://www.qtcn.org/bbs/read.php?tid=23252&page=1&toread=1 下载到。 六、Qt Creator 实现文本编辑(原创) 前面已经将界面做好了,这里我们为其添加代码,实现文本编辑的功能。 首先实现新建文件,文件保存,和文件另存为的功能。 (我们先将上次的工程文件夹进行备份,然后再对其进行修改。在写较大的程序 时,经常对源文件进行备份,是个很好的习惯。) 在开始正式写程序之前,我们先要考虑一下整个流程。因为我们要写记事本一 样的软件,所以最好先打开windows 中的记事本,进行一些简单的操作,然后 考虑怎样去实现这些功能。再者,再强大的软件,它的功能也是一个一个加上 去的,不要设想一下子写出所有的功能。我们这里先实现新建文件,保存文件, 和文件另存为三个功能,是因为它们联系很紧,而且这三个功能总的代码量也 不是很大。 因为三个功能之间的关系并不复杂,所以我们这里便不再画流程图,而只是简 单描述一下。 新建文件,那么如果有正在编辑的文件,是否需要保存呢? 如果需要进行保存,那这个文件以前保存过吗?如果没有保存过,就应该先将其 另存为。 下面开始按这些关系写程序。 1.打开Qt Creator,在File 菜单中选择Open,然后在工程文件夹中打开 MainWindow.pro 工程文件。 先在main.cpp 文件中加入以下语句,让程序中可以使用中文。 在其中加入#include 头文件包含,再在主函数中加入下面一行: QTextCodec::setCodecForTr(QTextCodec::codecForLocale()); 这样在程序中使用中文,便能在运行时显示出来了。更改后文件如下图。 2.在mainwindow.h 文件中的private 下加入以下语句。 bool isSaved; //为true 时标志文件已经保存,为false 时标志文件尚未保存 QString curFile; //保存当前文件的文件名 void do_file_New(); //新建文件 void do_file_SaveOrNot(); //修改过的文件是否保存 void do_file_Save(); //保存文件 void do_file_SaveAs(); //文件另存为 bool saveFile(const QString& fileName); //存储文件 这些是变量和函数的声明。其中isSaved 变量起到标志的作用,用它来标志文件 是否被保存过。然后我们再在相应的源文件里进行这些函数的定义。 3.在mainwindow.cpp 中先加入头文件#include ,然后在构造函数里添 加以下几行代码。 isSaved = false; //初始化文件为未保存过状态 curFile = tr("未命名.txt"); //初始化文件名为“未命名.txt” setWindowTitle(curFile); //初始化主窗口的标题 这是对主窗口进行初始化。效果如下。 4.然后添加“新建”操作的函数定义。 void MainWindow::do_file_New() //实现新建文件的功能 { do_file_SaveOrNot(); isSaved = false; curFile = tr("未命名.txt"); setWindowTitle(curFile); ui->textEdit->clear(); //清空文本编辑器 ui->textEdit->setVisible(true); //文本编辑器可见 } 新建文件,先要判断正在编辑的文件是否需要保存。然后将新建的文件标志为未 保存过状态。 5.再添加do_file_SaveOrNot 函数的定义。 void MainWindow::do_file_SaveOrNot() //弹出是否保存文件对话框 { if(ui->textEdit->document()->isModified()) //如果文件被更改过,弹出保 存对话框 { QMessageBox box; box.setWindowTitle(tr("警告")); box.setIcon(QMessageBox::Warning); box.setText(curFile + tr(" 尚未保存,是否保存?")); box.setStandardButtons(QMessageBox::Yes | QMessageBox::No); if(box.exec() == QMessageBox::Yes) //如果选择保存文件,则执行保存操作 do_file_Save(); } } 这个函数实现弹出一个对话框,询问是否保存正在编辑的文件。 6.再添加“保存”操作的函数定义。 void MainWindow::do_file_Save() //保存文件 { if(isSaved){ //如果文件已经被保存过,直接保存文件 saveFile(curFile); } else{ do_file_SaveAs(); //如果文件是第一次保存,那么调用另存为 } } 对文件进行保存时,先判断其是否已经被保存过,如果没有被保存过,就要先对 其进行另存为操作。 7.下面是“另存为”操作的函数定义。 void MainWindow::do_file_SaveAs() //文件另存为 { QString fileName = QFileDialog::getSaveFileName(this,tr("另存为 "),curFile); //获得文件名 if(!fileName.isEmpty()) //如果文件名不为空,则保存文件内容 { saveFile(fileName); } } 这里弹出一个文件对话框,显示文件另存为的路径。 8.下面是实际文件存储操作的函数定义。 bool MainWindow::saveFile(const QString& fileName) //保存文件内容,因为可能保存失败,所以具有返回值,来表明是否保存成功 { QFile file(fileName); if(!file.open(QFile::WriteOnly | QFile::Text)) //以只写方式打开文件,如果打开失败则弹出提示框并返回 { QMessageBox::warning(this,tr("保存文件"), tr("无法保存文件 %1:\n %2").arg(fileName) .arg(file.errorString())); return false; } //%1,%2 表示后面的两个arg 参数的值 QTextStream out(&file); //新建流对象,指向选定的文件 out << ui->textEdit->toPlainText(); //将文本编辑器里的内容以纯文本 的形式输出到流对象中 isSaved = true; curFile = QFileInfo(fileName).canonicalFilePath(); //获得文件的标准路 径 setWindowTitle(curFile); //将窗口名称改为现在窗口的路径 return true; } 这个函数实现将文本文件进行存储。下面我们对其中的一些代码进行讲解。 QFile file(fileName);一句,定义了一个QFile 类的对象file,其中filename 表明这个文件就是我们保存的的文件。然后我们就可以用file 代替这个文件, 来进行一些操作。Qt 中文件的操作和C,C++很相似。对于QFile 类对象怎么使 用,我们可以查看帮助。 点击Qt Creator 最左侧的Help,在其中输入QFile, 在搜索到的列表中选择QFile 即可。这时在右侧会显示出QFile 类中所有相关信 息以及他们的用法和说明。 // 我们往下拉,会发现下面有关于怎么读取文件的示例代码。 // // 再往下便能看到用QTextStream 类对象,进行字符串输入的例子。下面也提到了 QFileInfo 和QDir 等相关的类,我们可以点击它们去看一下具体的使用说明。 // 上面只是做了一个简单的说明。以后我们对自己不明白的类都可以去帮助里进行 查找,这也许是我们以后要做的最多的一件事了。对于其中的英文解释,我们最 好想办法弄明白它的大意,其实网上也有一些中文的翻译,但最好还是从一开始 就尝试着看英文原版的帮助,这样以后才不会对中文翻译产生依赖。 我们这次只是很简单的说明了一下怎样使用帮助文件,这不表明 它不重要,而是因为这里不可能将每个类的帮助都解释一遍,没有那么多时间, 也没有那么大的篇幅。而更重要的是因为,我们这个教程只是引你入门,所以很 多东西需要自己去尝试。 在以后的教程里,如果不是特殊情况,就不会再对其中的类进行 详细解释,文章中的重点是对整个程序的描述,其中不明白的类,自己查看帮助。 9.双击mainwindow.ui 文件,在图形界面窗口下面的Action Editor 动作编辑 器里,我们右击“新建”菜单一条,选择Go to slot,然后选择triggered(), 进入其触发事件槽函数。 同理,进入其他两个菜单的槽函数,将相应的操作的函数写入槽函数中。如下。 void MainWindow::on_action_New_triggered() //信号和槽的关联 { do_file_New(); } void MainWindow::on_action_Save_triggered() { do_file_Save(); } void MainWindow::on_action_SaveAs_triggered() { do_file_SaveAs(); } 这时点击运行,就能够实现新建文件,保存文件,文件另存为的功能了。 然后实现打开,关闭,退出,撤销,复制,剪切,粘贴的功能。 先备份上次的工程文件,然后再将其打开。 1.先在mainwindow.h 文件中加入函数的声明。 void do_file_Open(); //打开文件 bool do_file_Load(const QString& fileName); //读取文件 2.再在mainwindow.cpp 文件中写函数的功能实现。 void MainWindow::do_file_Open()//打开文件 { do_file_SaveOrNot();//是否需要保存现有文件 QString fileName = QFileDialog::getOpenFileName(this); //获得要打开的文件的名字 if(!fileName.isEmpty())//如果文件名不为空 { do_file_Load(fileName); } ui->textEdit->setVisible(true);//文本编辑器可见 } bool MainWindow::do_file_Load(const QString& fileName) //读取文件 { QFile file(fileName); if(!file.open(QFile::ReadOnly | QFile::Text)) { QMessageBox::warning(this,tr("读取文件"),tr("无法读取文件 %1:\n%2.").arg(fileName).arg(file.errorString())); return false; //如果打开文件失败,弹出对话框,并返回 } QTextStream in(&file); ui->textEdit->setText(in.readAll()); //将文件中的所有内容都 写到文本编辑器中 curFile = QFileInfo(fileName).canonicalFilePath(); setWindowTitle(curFile); return true; } 上面的打开文件函数与文件另存为函数相似,读取文件的函数与文件存储函数相 似。 3.然后按顺序加入更菜单的关联函数,如下。 void MainWindow::on_action_Open_triggered() //打开操作 { do_file_Open(); } // void MainWindow::on_action_Close_triggered() //关闭操作 { do_file_SaveOrNot(); ui->textEdit->setVisible(false); } // void MainWindow::on_action_Quit_triggered() //退出操作 { on_action_Close_triggered(); //先执行关闭操作 qApp->quit(); //再退出系统,qApp 是指向应用程序的全局指针 } // void MainWindow::on_action_Undo_triggered() //撤销操作 { ui->textEdit->undo(); } // void MainWindow::on_action_Cut_triggered() //剪切操作 { ui->textEdit->cut(); } // void MainWindow::on_action_Copy_triggered() //复制操作 { ui->textEdit->copy(); } // void MainWindow::on_action_Past_triggered() //粘贴操作 { ui->textEdit->paste(); } 因为复制,撤销,全选,粘贴,剪切等功能,是TextEdit 默认就有的,所以我 们只需调用一下相应函数就行。 到这里,除了查找和帮助两个菜单的功能没有加上以外,其他功能都已经实现了。 七、Qt Creator 实现文本查找(原创) 现在加上查找菜单的功能。因为这里要涉及关于Qt Creator 的很多实用功能, 所以单独用一篇文章来介绍。 以前都用设计器设计界面,而这次我们用代码实现一个简单的查找对话框。对于 怎么实现查找功能的,我们详细地分步说明了怎么进行类中方法的查找和使用。 其中也将Qt Creator 智能化的代码补全功能和程序中函数的声明位置和定义位 置间的快速切换进行了介绍。 1.首先还是保存以前的工程,然后再将其打开。 我们发现Qt Creator 默认的字体有点小,可以按下Ctrl 键的同时按两下+键, 来放大字体。也可以选择Edit->Advanced->Increase Font Size。 2.在mainwindow.h 中加入#include 的头文件包含,在private 中 添加 QLineEdit *find_textLineEdit; //声明一个行编辑器,用于输入要查找的内容 在private slots 中添加 void show_findText(); 在该函数中实现查找字符串的功能。 3.我们进入查找菜单的触发事件槽函数,更改如下。 void MainWindow::on_action_Find_triggered() { QDialog *findDlg = new QDialog(this); //新建一个对话框,用于查找操作,this 表明它的父窗口是MainWindow。 findDlg->setWindowTitle(tr("查找")); //设置对话框的标题 find_textLineEdit = new QLineEdit(findDlg); //将行编辑器加入到新建的查找对话框中 QPushButton *find_Btn = new QPushButton(tr("查找下一个"),findDlg); //加入一个“查找下一个”的按钮 QVBoxLayout* layout = new QVBoxLayout(findDlg); layout->addWidget(find_textLineEdit); layout->addWidget(find_Btn); //新建一个垂直布局管理器,并将行编辑器和按钮加入其中 findDlg ->show(); //显示对话框 connect(find_Btn,SIGNAL(clicked()),this,SLOT(show_findText())); //设置“查找下一个”按钮的单击事件和其槽函数的关联 } 这里我们直接用代码生成了一个对话框,其中一个行编辑器可以输入要查找的字 符,一个按钮可以进行查找操作。我们将这两个部件放到了一个垂直布局管理器 中。然后显示这个对话框。并设置了那个按钮单击事件与show_findText()函数 的关联。 5.下面我们开始写实现查找功能的show_findText()函数。 void MainWindow::show_findText()//“查找下一个”按钮的槽函数 { QString findText = find_textLineEdit->text(); //获取行编辑器中的内容 } 先用一个QString 类的对象获得要查找的字符。然后我们一步一步写查找操作的 语句。 6.在下一行写下ui,然后直接按下键盘上的“<.”键,这时系统会根据是否是 指针对象而自动生成“->”或“.”,因为ui 是指针对象,所以自动生成“->” 号,而且弹出了ui 中的所有部件名称的列表。如下图。 7.我们用向下的方向键选中列表中的textEdit。或者我们可以先输入text,这 时能缩减列表的内容。 8.如上图我们将鼠标放到textEdit 上,这时便出现了textEdit 的类名信息, 且后面出现一个F1 按键。我们按下键盘上的F1,便能出现textEdit 的帮助。 9.我们在帮助中向下拉,会发现这里有一个find 函数。 10.我们点击find,查看其详细说明。 11.可以看到find 函数可以实现文本编辑器中字符串的查找。其中有一个 FindFlags 的参数,我们点击它查看其说明。 12.可以看到它是一个枚举变量(enum),有三个选项,第一项是向后查找(即 查找光标以前的内容,这里的前后是相对的说法,比如第一行已经用完了,光 标在第二行时,把第一行叫做向后。),第二项是区分大小写查找,第三项是 查找全部。 13.我们选用第一项,然后写出下面的语句。 ui->textEdit->find(findText,QTextDocument::FindBackward); //将行编辑器中的内容在文本编辑器中进行查找 当我们刚打出“f”时,就能自动弹出textEdit 类的相关属性和方法。 可以看到,当写完函数名和第一个“(”后,系统会自动显示出该函数的函数原 型,这样可以使我们减少出错。 14.这时已经能实现查找的功能了。但是我们刚才看到find 的返回值类型是bool 型,而且,我们也应该为查找不到字符串作出提示。 if(!ui->textEdit->find(findText,QTextDocument::FindBackward)) { QMessageBox::warning(this,tr("查找"),tr("找不到 %1") .arg(findText); } 因为查找失败返回值是false,所以if 条件加了“!”号。在找不到时弹出警 告对话框。 15.到这里,查找功能就基本上写完了。show_findText()函数的内容如下。 我们会发现随着程序功能的增强,其中的函数也会越来越多,我们都会为查找 某个函数的定义位置感到头疼。而在Qt Creator 中有几种快速定位函数的方法, 我们这里讲解三种。 第一,在函数声明的地方直接跳转到函数定义的地方。 如在do_file_Load 上点击鼠标右键,在弹出的菜单中选择Follow Symbol under Cursor 或者下面的Switch between Method Declaration/Definition。 这时系统就会自动跳转到函数定义的位置。如下图。 第二,快速查找一个文件里的所有函数。 我们可以点击窗口最上面的下拉框,这里会显示本文件中所有函数的列表。 第三,利用查找功能。 1.我们先将鼠标定位到一个函数名上。 2.然后选择Edit->Find/Replace->Find Dialog。 3.这时会出现一个查找对话框,可以看到要查找的函数名已经写在里面了。 4.当我们按下Search 按钮后,会在查找结果窗口显示查找到的结果。 5.我们点击第二个文件。会发现在这个文件中有两处关键字是高亮显示。 6.我们双击第二项,就会自动跳转到函数的定义处。 文章讲到这里,我们已经很详细地说明了怎样去使用一个类里面没有用过的方法 函数;也说明了Qt Creator 中的一些便捷操作。可以看到,Qt Creator 开发环 境,有很多很人性化的设计,我们应该熟练应用它们。 在以后的文章中,我们不会再很详细地去用帮助来说明一个函数是 怎么来的,该怎么用,这些应该自己试着去查找。 八、Qt Creator 实现状态栏显示(原创) 在程序主窗口Mainwindow 中,有菜单栏,工具栏,中心部件和状态栏。前面几 个已经讲过了,这次讲解状态栏的使用。 程序中有哪些不明白的类或函数,请自己查看帮助。 1.我们在mainwindow.h 中做一下更改。 加入头文件包含: #include 加入私有变量和函数: QLabel* first_statusLabel; //声明两个标签对象,用于显示状态信息 QLabel* second_statusLabel; void init_statusBar(); //初始化状态栏 加入一个槽函数声明:void do_cursorChanged(); //获取光标位置信息 2.在mainwindow.cpp 中加入状态栏初始化函数的定义。 void MainWindow::init_statusBar() { QStatusBar* bar = ui->statusBar; //获取状态栏 first_statusLabel = new QLabel; //新建标签 first_statusLabel->setMinimumSize(150,20); //设置标签最小尺寸 first_statusLabel->setFrameShape(QFrame::WinPanel); //设置标签形状 first_statusLabel->setFrameShadow(QFrame::Sunken); //设置标签阴影 second_statusLabel = new QLabel; second_statusLabel->setMinimumSize(150,20); second_statusLabel->setFrameShape(QFrame::WinPanel); second_statusLabel->setFrameShadow(QFrame::Sunken); bar->addWidget(first_statusLabel); bar->addWidget(second_statusLabel); first_statusLabel->setText(tr("欢迎使用文本编辑器")); //初始化内容 second_statusLabel->setText(tr("yafeilinux 制作!")); } 这里将两个标签对象加入到了主窗口的状态栏里,并设置了他们的外观和初值。 3.在构造函数里调用状态栏初始化函数。 init_statusBar(); 这时运行程序,效果如下。 4.在mainwindow.cpp 中加入获取光标位置的函数的定义。 void MainWindow::do_cursorChanged() { int rowNum = ui->textEdit->document()->blockCount(); //获取光标所在行的行号 const QTextCursor cursor = ui->textEdit->textCursor(); int colNum = cursor.columnNumber(); //获取光标所在列的列号 first_statusLabel->setText(tr("%1 行 %2 列").arg(rowNum).arg(colNum)); //在状态栏显示光标位置 } 这个函数可获取文本编辑框中光标的位置,并显示在状态栏中。 5.在构造函数添加光标位置改变信号的关联。 connect(ui->textEdit,SIGNAL(cursorPositionChanged()),this,SLOT(do_cur sorChanged())); 这时运行程序。效果如下。 6.在do_file_Load 函数的最后添加下面语句。 second_statusLabel->setText(tr("打开文件成功")); 7.在saveFile 函数的最后添加以下语句。 second_statusLabel->setText(tr("保存文件成功")); 8.在on_action_Find_triggered 函数的后面添加如下语句。 second_statusLabel->setText(tr("正在进行查找")); 9.在on_action_Close_triggered 函数最后添加如下语句。 first_statusLabel->setText(tr("文本编辑器已关闭")); second_statusLabel->setText(tr("yafeilinux 制作!")); 到这里整个文本编辑器的程序就算写完了。我们这里没有写帮助菜单的功能实 现,大家可以自己添加。而且程序中也有很多漏洞和不完善的地方,如果有兴 趣,大家也可以自己修改。因为时间和篇幅的原因,我们这里就不再过多的讲 述。 九、Qt Creator 中鼠标键盘事件的处理实现自定义鼠标指针(原创) 我们前面一直在说信号,比方说用鼠标按了一下按钮,这样就会产生一个按钮的 单击信号,然后我们可以在相应的槽函数里进行相应功能的设置。其实在按下鼠 标后,程序要先接收到鼠标按下的事件,然后将这个事件按默认的设置传给按钮。 可以看出,事件和信号并不是一回事,事件比信号更底层。而我们以前把单击按 钮也叫做事件,这是不确切的,不过大家都知道是什么意思,所以当时也没有细 分。 Qt 中的事件可以在QEvent 中查看。下面我们只是找两个例子来进行简单的演示。 1.还是先建立一个Qt4 Gui Application 工程,我这里起名为event。 2.添加代码,让程序中可以使用中文。 即在main.cpp 文件中加入#include 的头文件包含。 再在下面的主函数里添加 QTextCodec::setCodecForTr(QTextCodec::codecForLocale()); 3.在mainwindow.h 文件中做一下更改。 添加#include 头文件。因为这样就包含了QtGui 中所有的子文件。 在public 中添加两个函数的声明 void mouseMoveEvent(QMouseEvent *); void keyPressEvent(QKeyEvent *); 4.我们在mainwindow.ui 中添加一个Label 和一个PushButton,将他们拉长点, 因为一会要在上面显示标语。 5.在mainwindow.cpp 中的构造函数里添加两个部件的显示文本。 ui->label->setText(tr("按下键盘上的A 键试试!")); ui->pushButton->setText(tr("按下鼠标的一个键,然后移动鼠标试试")); 6.然后在下面进行两个函数的定义。 /*以下是鼠标移动事件*/ void MainWindow::mouseMoveEvent(QMouseEvent *m) {//这里的函数名和参数不能更改 QCursor my(QPixmap("E:/Qt/Qt-Creator-Example/event/time.png")); //为鼠标指针选择图片,注意这里要用绝对路径,且要用“/”,而不能用“\” QApplication::setOverrideCursor(my); //将鼠标指针更改为自己设置的图片 int x = m->pos().x(); int y = m->pos().y(); //获取鼠标现在的位置坐标 ui->pushButton->setText(tr("鼠标现在的坐标是(%1,%2), 哈哈好玩吧 ").arg(x).arg(y)); //将鼠标的位置坐标显示在按钮上 ui->pushButton->move(m->pos()); //让按钮跟随鼠标移动 } /*以下是键盘按下事件*/ void MainWindow::keyPressEvent(QKeyEvent *k) { if(k->key() == Qt::Key_A) //判断是否是A 键按下 { ui->label->setPixmap(QPixmap("E:/Qt/Qt-Creator-Example/event/linux.jp g")); ui->label->resize(100,100); //更改标签图片和大小 } } 注意:这两个函数不是自己新建的,而是对已有函数的重定义,所有函数名和参 数都不能改。第一个函数对鼠标移动事件进行了重写。其中实现了鼠标指针的更 改,和按钮跟随鼠标移动的功能。 第二个函数对键盘的A 键按下实现了新的功能。 效果如下。 按下鼠标的一个键,并移动鼠标。 按下键盘上的A 键。 十、Qt Creator 中实现定时器和产生随机数(原创) 有两种方法实现定时器。 第一种。自己建立关联。 1.新建Gui 工程,工程名可以设置为timer。并在主界面上添加一个标签label, 并设置其显示内容为“0000-00-00 00:00:00 星期日”。 2.在mainwindow.h 中添加槽函数声明。 private slots: void timerUpDate(); 3.在mainwindow.cpp 中添加代码。 添加#include 的头文件包含,这样就包含了QtCore 下的所有文件。 构造函数里添加代码: QTimer *timer = new QTimer(this); //新建定时器 connect(timer,SIGNAL(timeout()),this,SLOT(timerUpDate())); //关联定时器计满信号和相应的槽函数 timer->start(1000); //定时器开始计时,其中1000 表示1000ms 即1 秒 4.然后实现更新函数。 void MainWindow::timerUpDate() { QDateTime time = QDateTime::currentDateTime(); //获取系统现在的时间 QString str = time.toString("yyyy-MM-dd hh:mm:ss dddd"); //设置系统时间显示格式 ui->label->setText(str); //在标签上显示时间 } 5.运行程序,效果如下。 第二种。使用事件。(有点像单片机中的定时器啊) 1.新建工程。在窗口上添加两个标签。 2.在main.cpp 中添加代码,实现中文显示。 #include QTextCodec::setCodecForTr(QTextCodec::codecForLocale()); 3.在mainwindow.h 中添加代码。 void timerEvent(QTimerEvent *); 4.在mainwindow.cpp 中添加代码。 添加头文件#include 在构造函数里添加以下代码。 startTimer(1000); //其返回值为1,即其timerId 为1 startTimer(5000);//其返回值为2,即其timerId 为2 startTimer(10000); //其返回值为3,即其timerId 为3 添加了三个定时器,它们的timerId 分别为1,2,3。注意,第几个定时器的返 回值就为几。所以要注意定时器顺序。 在下面添加函数实现。 void MainWindow::timerEvent(QTimerEvent *t) //定时器事件 { switch(t->timerId()) //判断定时器的句柄 { case 1 : ui->label->setText(tr("每秒产生一个随机数: %1").arg(qrand()%10));break; case 2 : ui->label_2->setText(tr("5 秒后软件将关闭"));break; case 3 : qApp->quit();break; //退出系统 } } 这里添加了三个定时器,并都在定时器事件中判断它们,然后执行相应的功能。 这样就不用每个定时器都写一个关联函数和槽函数了。 随机数的实现: 上面程序中的qrand(),可以产生随机数,qrand()%10 可以产生0-9 之间的随机 数。要想产生100 以内的随机数就%100。以此类推。 但这样每次启动程序后,都按同一种顺序产生随机数。为了实现每次启动程序产 生不同的初始值。我们可以使用qsrand(time(0));实现设置随机数的初值,而 程序每次启动时time(0)返回的值都不同,这样就实现了产生不同初始值的功 能。 我们将qsrand(time(0));一句加入构造函数里。 程序最终运行效果如下。 十一、Qt 2D 绘图(一)绘制简单图形(原创) 声明:本文原创于yafeilinux 的百度博客,http://hi.baidu.com/yafeilinux 转载请注明出处。 说明:以后使用的环境为基于Qt 4.6 的Qt Creator 1.3.0 windows 版本 本文介绍在窗口上绘制最简单的图形的方法。 1.新建Qt4 Gui Application 工程,我这里使用的工程名为painter01,选用 QDialog 作为Base class 2.在dialog.h 文件中声明重绘事件函数void paintEvent(QPaintEvent *); 3.在dialog.cpp 中添加绘图类QPainter 的头文件包含#include 4.在下面进行该函数的重定义。 void Dialog::paintEvent(QPaintEvent *) { QPainter painter(this); painter.drawLine(0,0,100,100); } 其中创建了QPainter 类对象,它是用来进行绘制图形的,我们这里画了一条线 Line,其中的参数为线的起点(0,0),和终点(100,100)。这里的数值指的 是像素,详细的坐标设置我们以后再讲,这里知道(0,0)点指的是窗口的左上 角即可。运行效果如下: 5.在qt 的帮助里可以查看所有的绘制函数,而且下面还给出了相关的例子。 6.我们下面将几个知识点说明一下,帮助大家更快入门。 将函数改为如下: void Dialog::paintEvent(QPaintEvent *) { QPainter painter(this); QPen pen; //画笔 pen.setColor(QColor(255,0,0)); QBrush brush(QColor(0,255,0,125)); //画刷 painter.setPen(pen); //添加画笔 painter.setBrush(brush); //添加画刷 painter.drawRect(100,100,200,200); //绘制矩形 } 这里的pen 用来绘制边框,brush 用来进行封闭区域的填充,QColor 类用来提供 颜色,我们这里使用了rgb 方法来生成颜色,即(red,green,blue),它们取 值分别是0-255,例如(255,0,0)表示红色,而全0 表示黑色,全255 表示 白色。后面的(0,255,0,125),其中的125 是透明度(alpha)设置,其值 也是从0 到255,0 表示全透明。最后将画笔和画刷添加到painter 绘制设备中, 画出图形。这里的Rect 是长方形,其中的参数为(100,100)表示起始坐标, 200,200 表示长和宽。效果如下: 7.其实画笔和画刷也有很多设置,大家可以查看帮助。 QPainter painter(this); QPen pen(Qt::DotLine); QBrush brush(Qt::blue); brush.setStyle(Qt::HorPattern); painter.setPen(pen); painter.setBrush(brush); painter.drawRect(100,100,200,200); 这里我们设置了画笔的风格为点线,画刷的风格为并行横线,效果如下: 在帮助里可以看到所有的风格。 我们这里用了Qt::blue,Qt 自定义的几个颜色如下: 8.画弧线,这是帮助里的一个例子。 QRectF rectangle(10.0, 20.0, 80.0, 60.0); //矩形 int startAngle = 30 * 16; //起始角度 int spanAngle = 120 * 16; //跨越度数 QPainter painter(this); painter.drawArc(rectangle, startAngle, spanAngle); 这里要说明的是,画弧线时,角度被分成了十六分之一,就是说,要想为30 度, 就得是30*16。它有起始角度和跨度,还有位置矩形,要想画出自己想要的弧线, 就要有一定的几何知识了。这里就不再祥述。 十二、Qt 2D 绘图(二)渐变填充(原创) 声明:本文原创于yafeilinux 的百度博客,http://hi.baidu.com/yafeilinux 转载请注明出处。 在qt 中提供了三种渐变方式,分别是线性渐变,圆形渐变和圆锥渐变。如果能 熟练应用它们,就能设计出炫目的填充效果。 线性渐变: 1.更改函数如下: void Dialog::paintEvent(QPaintEvent *) { QPainter painter(this); QLinearGradient linearGradient(100,150,300,150); //从点(100,150)开始到点(300,150)结束,确定一条直线 linearGradient.setColorAt(0,Qt::red); linearGradient.setColorAt(0.2,Qt::black); linearGradient.setColorAt(0.4,Qt::yellow); linearGradient.setColorAt(0.6,Qt::white); linearGradient.setColorAt(0.8,Qt::green); linearGradient.setColorAt(1,Qt::blue); //将直线开始点设为0,终点设为1,然后分段设置颜色 painter.setBrush(linearGradient); painter.drawRect(100,100,200,100); //绘制矩形,线性渐变线正好在矩形的水平中心线上 } 效果如下: 圆形渐变: 1.更改函数内容如下: QRadialGradient radialGradient(200,100,100,200,100); //其中参数分别为圆形渐变的圆心(200,100),半径100,和焦点(200, 100) //这里让焦点和圆心重合,从而形成从圆心向外渐变的效果 radialGradient.setColorAt(0,Qt::black); radialGradient.setColorAt(1,Qt::yellow); //渐变从焦点向整个圆进行,焦点为起始点0,圆的边界为1 QPainter painter(this); painter.setBrush(radialGradient); painter.drawEllipse(100,0,200,200); //绘制圆,让它正好和上面的圆形渐变的圆重合 效果如下: 2.要想改变填充的效果,只需要改变焦点的位置和渐变的颜色位置即可。 改变焦点位置:QRadialGradient radialGradient(200,100,100,100,100); 效果如下: 锥形渐变: 1.更改函数内容如下: //圆锥渐变 QConicalGradient conicalGradient(50,50,0); //圆心为(50,50),开始角度为0 conicalGradient.setColorAt(0,Qt::green); conicalGradient.setColorAt(1,Qt::white); //从圆心的0 度角开始逆时针填充 QPainter painter(this); painter.setBrush(conicalGradient); painter.drawEllipse(0,0,100,100); 效果如下: 2.可以更改开始角度,来改变填充效果 QConicalGradient conicalGradient(50,50,30); 开始角度设置为30 度,效果如下: 其实三种渐变的设置都在于焦点和渐变颜色的位置,如果想设计出漂亮的渐变 效果,还要有美术功底啊! 十二、Qt 2D 绘图(三)绘制文字(原创) 声明:本文原创于yafeilinux 的百度博客,http://hi.baidu.com/yafeilinux 转载请注明出处。 接着上一次的教程,这次我们学习在窗体上绘制文字。 1.绘制最简单的文字。 我们更改重绘函数如下: void Dialog::paintEvent(QPaintEvent *) { QPainter painter(this); painter.drawText(100,100,"yafeilinux"); } 我们在(100,100)的位置显示了一行文字,效果如下。 2.为了更好的控制字体的位置。我们使用另一个构造函数。在帮助里查看 drawText,如下。 这里我们看到了构造函数的原型和例子。其中的flags 参数可以控制字体在矩形 中的位置。我们更改函数内容如下。 void Dialog::paintEvent(QPaintEvent *) { QPainter painter(this); QRectF ff(100,100,300,200); //设置一个矩形 painter.drawRect(ff); //为了更直观地看到字体的位置,我们绘制出这个矩形 painter.setPen(QColor(Qt::red)); //设置画笔颜色为红色 painter.drawText(ff,Qt::AlignHCenter,"yafeilinux"); //我们这里先让字体水平居中 } 效果如下。 可以看到字符串是在最上面水平居中的。如果想让其在矩形正中间,我们可以使 用Qt::AlignCenter。 这里我们也可以使用两个枚举变量进行按位与操作,例如可以使用 Qt::AlignBottom|Qt::AlignHCenter 实现让文字显示在矩形下面的正中间。效 果如下。 对于较长的字符串,我们也可以利用“\n”进行换行,例如"yafei\nlinux"。效 果如下。 3.如果要使文字更美观,我们就需要使用QFont 类来改变字体。先在帮助中查 看一下这个类。 可以看到它有好几个枚举变量来设置字体。下面的例子我们对主要的几个选项进 行演示。 更改函数如下。 void Dialog::paintEvent(QPaintEvent *) { QFont font("Arial",20,QFont::Bold,true); //设置字体的类型,大小,加粗,斜体 font.setUnderline(true); //设置下划线 font.setOverline(true); //设置上划线 font.setCapitalization(QFont::SmallCaps); //设置大小写 font.setLetterSpacing(QFont::AbsoluteSpacing,5); //设置间距 QPainter painter(this); painter.setFont(font); //添加字体 QRectF ff(100,100,300,200); painter.drawRect(ff); painter.setPen(QColor(Qt::red)); painter.drawText(ff,Qt::AlignCenter,"yafeilinux"); } 效果如下。 这里的所有字体我们可以在设计器中进行查看。如下。 基于Qt 4.6 的Qt Creator 1.3.0 环境变量设置(原创) 如果你以前安装过visual studio 2005 之类的软件,那么装上Qt Creator 1.3.0 后,编译运行其自带的演示程序时就可能出现如下图的,105 个错误,几十个警 告的问题。 我们查看输出窗口,如下图。会发现它居然显示VC98 之类的东西,就是说它并 没有去自己的include 文件夹 中查找文件。我们可以怀疑是系统环境变量的问题了。 点击Qt Creator 界面左侧的projects 图标,查看工程信息。这里我们主要查看 编辑环境Buid Environment,点击其右侧的show Details。 可以看到其中的include 和lib 均指向了virtual studio 文件夹中,我们需要 将其改正。 将他们都改为自己Qt Creator 安装目录下的相关路径,如下图。(要换成你的 安装路径) 改完后会发现新的设置已经显示出来了。 我们查看下面的Run Environment,发现它已经自己改过来了。 回到编辑界面,右击工程文件,在弹出的菜单上选择Clean project,清空以前 的编译信息。 然后运行Run qmake,生成Makefile 文件。 最后,点击run 或者build 都可,这时程序已经能正常编译运行了。 基于Qt 4.6 的Qt Creator 1.3.0 写helloworld 程序注意事项(原创) 注意:下面指的是在windows 下,linux 下的情况可进行相应改变 昨天Qt 4.6 和Qt Creator 1.3.0 正式版发布了,但是如果以前用过旧版本,就 可能出一些问题。 1.用debug 方式 如果你以前用了Qt 4.5 的Qt Creator,并且将QtCored4.dll,QtGuid4.dll, mingwm10.dll 等文件放到了C 盘的system 文件夹下。那么请先将它们删除,不 然编译不会通过。 编译完helloworld 程序后,如果要直接执行exe 文件,需要将安装目录(新版 Qt)下的qt/bin 目录下的QtCored4.dll,QtGuid4.dll,mingwm10.dll,和 libgcc_s_dw2-1.dll(这个是新增的)文件放在exe 文件夹中。或者将它们放到 系统的system 文件夹下。 2.选择release 方式 编译程序后生成exe 文件 1.需要Qt 安装目录下的qt/bin 目录中的QtGui4.dll ,Qt Core4.dll, libgcc_s_dw2-1.dll 以及mingwm10.dll 四个文件的支持,将它们拷贝到exe 文 件目录下。 2.程序中默认只支持png 图片,如果使用了gif,jpg 等格式的文件是显示不出 来的。需要将Qt 安装目录下的qt/plugins/目录中的imageformats 文件夹拷贝 到exe 文件目录下(注意是整个文件夹)。而imageformats 文件夹中只需要保 留你需要的文件,例如你只需要支持gif 文件,就只保留qgif4.dll 即可。 ‘Qt Creator 发布release 软件相关注意事项(原创) 注意:环境是windows 选择release 编译程序后生成exe 文件 1.需要Qt 安装目录下的qt/bin 目录中的QtGui4.dll 和 Qt Core4.dll 以及 mingwm10.dll 三个文件的支持,将它们拷贝到exe 文件目录下。 2.程序中默认只支持png 图片,如果使用了gif,jpg 等格式的文件是显示不出 来的。需要将Qt 安装目录下的qt/plugins/目录中的imageformats 文件夹拷贝 到exe 文件目录下(注意是整个文件夹)。而imageformats 文件夹中只需要保 留你需要的文件,例如你只需要支持gif 文件,就只保留qgif4.dll 即可。 Qt Creator 的 error: collect2: ld returned 1 exit status 问题 利用Qt Creator 1.2.1( Built on Sep 30 2009 at 05:21:42)编译 程序经常会出现error: collect2: ld returned 1 exit status 的错误,但是 自己的程序没有一点问题,怎么回事呢? 如果这时退出软件,再重新进入,打开刚才的工程,重新编译, 就不会出现刚才的错误了。这应该是Qt Creator 软件的问题吧! 后来发现是因为上次执行的程序还在运行,你打开windows 的任 务管理器中的进程可以看见你刚才运行的程序还在执行,我们看不见,是因为它 在后台执行着。出现这个现象,是因为你写的代码的问题,比如在main 函数里 用了w.show();语句,就可能出现界面一闪而过,但它并没有关闭,而是在后台 运行,所以再次运行时就会出错。我们可以在资源管理器中将该进程关闭,或者 像上面那样直接关闭Qt Creator。 示例: #include #include "widget.h" #include "logindlg.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); loginDlg m; if(m.exec()==QDialog::Accepted) { Widget w; w.show(); } return a.exec(); } 执行后就会在后台运行。这时如果修改了代码再次运行程序,就会出现上面的错 误。 在任务管理器中可以看见自己的程序: 将该进程结束,然后在重新运行,就不会出错了。 正确的代码应该这样写: int main(int argc, char *argv[]) { QApplication a(argc, argv); loginDlg m; Widget w; if(m.exec()==QDialog::Accepted) { w.show(); return a.exec(); } else return 0; //关闭整个程序 } 这样新建的对象w 就不是局部变量了,这样运行程序w 表示的窗口不会一闪而过, 会一直显示。程序也不会再出现上面的错误了。 QT 常用问题解答(转) 本文是我前几天一个网友告诉我的,当时看了感觉好,就保存下来。今天再次查 看,感觉有必要把文章分享给各位学习QT 的朋友,因为网上好用的QT 资源真的 好少。 1、如果在窗体关闭前自行判断是否可关闭 答:重新实现这个窗体的closeEvent()函数,加入判断操作 Quote: void MainWindow::closeEvent(QCloseEvent *event) { if (maybeSave()) { writeSettings(); event->accept(); } else { event->ignore(); } } 2、如何用打开和保存文件对话 答:使用QFileDialog Quote: QString fileName = QFileDialog::getOpenFileName(this); if (!fileName.isEmpty()) { loadFile(fileName); } Quote: QString fileName = QFileDialog::getSaveFileName(this); if (fileName.isEmpty()) { return false; } 3、如果创建Actions(可在菜单和工具栏里使用这些Action) 答: Quote: newAct = new QAction(QIcon(":/images/new.png"), tr("&New"), this); newAct->setShortcut(tr("Ctrl+N")); newAct->setStatusTip(tr("Create a new file")); connect(newAct, SIGNAL(triggered()), this, SLOT(newFile())); openAct = new QAction(QIcon(":/images/open.png"), tr("&Open..."), this); openAct->setShortcut(tr("Ctrl+O")); openAct->setStatusTip(tr("Open an existing file")); connect(openAct, SIGNAL(triggered()), this, SLOT(open())); saveAct = new QAction(QIcon(":/images/save.png"), tr("&Save"), this); saveAct->setShortcut(tr("Ctrl+S")); saveAct->setStatusTip(tr("Save the document to disk")); connect(saveAct, SIGNAL(triggered()), this, SLOT(save())); saveAsAct = new QAction(tr("Save &As..."), this); saveAsAct->setStatusTip(tr("Save the document under a new name")); connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs())); exitAct = new QAction(tr("E&xit"), this); exitAct->setShortcut(tr("Ctrl+Q")); exitAct->setStatusTip(tr("Exit the application")); connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); cutAct = new QAction(QIcon(":/images/cut.png"), tr("Cu&t"), this); cutAct->setShortcut(tr("Ctrl+X")); cutAct->setStatusTip(tr("Cut the current selection's contents to the " "clipboard")); connect(cutAct, SIGNAL(triggered()), textEdit, SLOT(cut())); copyAct = new QAction(QIcon(":/images/copy.png"), tr("&Copy"), this); copyAct->setShortcut(tr("Ctrl+C")); copyAct->setStatusTip(tr("Copy the current selection's contents to the " "clipboard")); connect(copyAct, SIGNAL(triggered()), textEdit, SLOT(copy())); pasteAct = new QAction(QIcon(":/images/paste.png"), tr("&Paste"), this); pasteAct->setShortcut(tr("Ctrl+V")); pasteAct->setStatusTip(tr("Paste the clipboard's contents into the current " "selection")); connect(pasteAct, SIGNAL(triggered()), textEdit, SLOT(paste())); aboutAct = new QAction(tr("&About"), this); aboutAct->setStatusTip(tr("Show the application's About box")); connect(aboutAct, SIGNAL(triggered()), this, SLOT(about())); aboutQtAct = new QAction(tr("About &Qt"), this); aboutQtAct->setStatusTip(tr("Show the Qt library's About box")); connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt())); 4、如果创建主菜单 答:采用上面的QAction 的帮助,创建主菜单 Quote: fileMenu = menuBar()->addMenu(tr("&File")); fileMenu->addAction(newAct); fileMenu->addAction(openAct); fileMenu->addAction(saveAct); fileMenu->addAction(saveAsAct); fileMenu->addSeparator(); fileMenu->addAction(exitAct); editMenu = menuBar()->addMenu(tr("&Edit")); editMenu->addAction(cutAct); editMenu->addAction(copyAct); editMenu->addAction(pasteAct); menuBar()->addSeparator(); helpMenu = menuBar()->addMenu(tr("&Help")); helpMenu->addAction(aboutAct); helpMenu->addAction(aboutQtAct); 5、如果创建工具栏 答:采用上面的QAction 的帮助,创建工具栏 Quote: fileToolBar = addToolBar(tr("File")); fileToolBar->addAction(newAct); fileToolBar->addAction(openAct); fileToolBar->addAction(saveAct); editToolBar = addToolBar(tr("Edit")); editToolBar->addAction(cutAct); editToolBar->addAction(copyAct); editToolBar->addAction(pasteAct); 6、如何使用配置文件保存配置 答:使用QSettings 类 Quote: QSettings settings("Trolltech", "Application Example"); QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint(); QSize size = settings.value("size", QSize(400, 400)).toSize(); Quote: QSettings settings("Trolltech", "Application Example"); settings.setValue("pos", pos()); settings.setValue("size", size()); 7、如何使用警告、信息等对话框 答:使用QMessageBox 类的静态方法 Quote: int ret = QMessageBox::warning(this, tr("Application"), tr("The document has been modified.\n" "Do you want to save your changes?"), QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape); if (ret == QMessageBox::Yes) return save(); else if (ret == QMessageBox::Cancel) return false; 8、如何使通用对话框中文化 答:对话框的中文化 比 如说,QColorDialog 的与文字相关的部分,主要在qcolordialog.cpp 文件 中,我们可以从qcolordialog.cpp 用 lupdate 生成一个ts 文件,然后用自定 义这个ts 文件的翻译,再用lrelease 生成一个.qm 文件,当然了,主程序就要 改变要支持多国语言了, 使用这个.qm 文件就可以了。 另外,还有一个更快的方法,在源代码解开后有一个目录translations,下面 有一些.ts, .qm 文件,我们拷贝一个: Quote: cp src/translations/qt_untranslated.ts ./qt_zh_CN.ts 然 后,我们就用Linguist 打开这个qt_zh_CN.ts,进行翻译了,翻译完成后, 保存后,再用lrelease 命令生成qt_zh_CN.qm, 这样,我们把它加入到我们的 qt project 中,那些系统的对话框,菜单等等其它的默认是英文的东西就能显 示成中文了。 9、在Windows 下Qt 里为什么没有终端输出? 答:把下面的配置项加入到.pro 文件中 Quote: win32:CONFIG += console 10、Qt 4 for X11 OpenSource 版如何静态链接? 答:编译安装的时候加上-static 选项 Quote: ./configure -static //一定要加static 选项 gmake gmake install 然后,在Makefile 文件中加 static 选项或者在.pro 文件中加上QMAKE_LFLAGS += -static,就可以连接静态库了。 11、想在源代码中直接使用中文,而不使用tr()函数进行转换,怎么办? 答:在main 函数中加入下面三条语句,但并不提倡 Quote: QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8")); 或者 Quote: QTextCodec::setCodecForLocale(QTextCodec::codecForName("GBK")); QTextCodec::setCodecForCStrings(QTextCodec::codecForName("GBK")); QTextCodec::setCodecForTr(QTextCodec::codecForName("GBK")); 使用GBK 还是使用UTF-8,依源文件中汉字使用的内码而定 这样,就可在源文件中直接使用中文,比如: Quote: QMessageBox::information(NULL, "信息", "关于本软件的演示信息", QMessageBox::Ok, QMessageBox::NoButtons); 12、为什么将开发的使用数据库的程序发布到其它机器就连接不上数据库? 答:这是由于程序找不到数据库插件而致,可照如下解决方法: 在main 函数中加入下面语句: Quote: QApplication::addLibraryPath(strPluginsPath"); strPluginsPath 是插件所在目录,比如此目录为/myapplication/plugins 则将需要的sql 驱动,比如qsqlmysql.dll, qsqlodbc.dll 或对应的.so 文件放 到 /myapplication/plugins/sqldrivers/ 目录下面就行了 这是一种解决方法,还有一种通用的解决方法,即在可执行文件目录下写 qt.conf 文件,把系统相关的一些目录配置写到qt.conf 文件里,详细情况情参 考Qt Document Reference 里的qt.conf 部分 13、如何创建QT 使用的DLL(.so)以及如何使用此DLL(.so) 答:创建DLL 时其工程使用lib 模板 Quote: TEMPLATE=lib 而源文件则和使用普通的源文件一样,注意把头文件和源文件分开,因为在其它 程序使用此DLL 时需要此头文件 在使用此DLL 时,则在此工程源文件中引入DLL 头文件,并在.pro 文件中加入 下面配置项: Quote: LIBS += -Lyourdlllibpath -lyourdlllibname Windows 下和Linux 下同样(Windows 下生成的DLL 文件名为yourdlllibname.dll 而在Linux 下生成的为libyourdlllibname.so。注意,关于DLL 程序的写法, 遵从各平台级编译器所定的规则。 14、如何启动一个外部程序 答:1、使用QProcess::startDetached()方法,启动外部程序后立即返回; 2、使用QProcess::execute(),不过使用此方法时程序会最阻塞直到此方法执 行的程序结束后返回
Table of Contents Summary of gdb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Free Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Free Software Needs Free Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Contributors to gdb. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1 A Sample gdb Session . . . . . . . . . . . . . . . . . . . . . . 7 2 Getting In and Out of gdb . . . . . . . . . . . . . . . . 11 2.1 Invoking gdb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.1.1 Choosing Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.1.2 Choosing Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.1.3 What gdb Does During Startup . . . . . . . . . . . . . . . . . . . . . . . . 2.2 Quitting gdb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.3 Shell Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.4 Logging Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 11 12 13 15 16 16 16 gdb Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 3.1 Command Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 3.2 Command Completion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 3.3 Getting Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 4 Running Programs Under gdb . . . . . . . . . . . . . 25 4.1 Compiling for Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.2 Starting your Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.3 Your Program’s Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.4 Your Program’s Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.5 Your Program’s Working Directory . . . . . . . . . . . . . . . . . . . . . . . . . . 4.6 Your Program’s Input and Output . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.7 Debugging an Already-running Process . . . . . . . . . . . . . . . . . . . . . . 4.8 Killing the Child Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.9 Debugging Programs with Multiple Threads . . . . . . . . . . . . . . . . . . 4.10 Debugging Programs with Multiple Processes. . . . . . . . . . . . . . . . 4.11 Setting a Bookmark to Return to Later . . . . . . . . . . . . . . . . . . . . . 4.11.1 A Non-obvious Benefit of Using Checkpoints . . . . . . . . . . . . 5 25 26 28 28 29 29 30 31 31 34 36 37 Stopping and Continuing . . . . . . . . . . . . . . . . . . 39 5.1 Breakpoints, Watchpoints, and Catchpoints . . . . . . . . . . . . . . . . . . 5.1.1 Setting Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.2 Setting Watchpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.3 Setting Catchpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.4 Deleting Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 40 45 47 49 ii Debugging with gdb 5.1.5 Disabling Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.6 Break Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.7 Breakpoint Command Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.8 “Cannot insert breakpoints” . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.9 “Breakpoint address adjusted...” . . . . . . . . . . . . . . . . . . . . . . . . 5.2 Continuing and Stepping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.3 Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4 Stopping and Starting Multi-thread Programs . . . . . . . . . . . . . . . . 6 Examining the Stack . . . . . . . . . . . . . . . . . . . . . . 61 6.1 6.2 6.3 6.4 7 Stack Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Backtraces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Selecting a Frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Information About a Frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 62 64 65 Examining Source Files . . . . . . . . . . . . . . . . . . . 67 7.1 Printing Source Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.2 Specifying a Location . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.3 Editing Source Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.3.1 Choosing your Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.4 Searching Source Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.5 Specifying Source Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.6 Source and Machine Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 49 50 52 53 53 54 57 59 67 68 69 69 70 70 72 Examining Data . . . . . . . . . . . . . . . . . . . . . . . . . . 75 8.1 Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.2 Ambiguous Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.3 Program Variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.4 Artificial Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.5 Output Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.6 Examining Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.7 Automatic Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.8 Print Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.9 Value History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.10 Convenience Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.11 Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.12 Floating Point Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.13 Vector Unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.14 Operating System Auxiliary Information . . . . . . . . . . . . . . . . . . . . 8.15 Memory Region Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.15.1 Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.15.1.1 Memory Access Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.15.1.2 Memory Access Size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.15.1.3 Data Cache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.15.2 Memory Access Checking. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.16 Copy Between Memory and a File . . . . . . . . . . . . . . . . . . . . . . . . . . 8.17 How to Produce a Core File from Your Program . . . . . . . . . . . . . 75 76 77 79 79 81 82 84 90 90 92 93 94 94 94 95 95 96 96 96 96 97 iii 8.18 Character Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 8.19 Caching Data of Remote Targets . . . . . . . . . . . . . . . . . . . . . . . . . . 100 8.20 Search Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 9 C Preprocessor Macros . . . . . . . . . . . . . . . . . . 103 10 Tracepoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 10.1 Commands to Set Tracepoints. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.1.1 Create and Delete Tracepoints . . . . . . . . . . . . . . . . . . . . . . . . 10.1.2 Enable and Disable Tracepoints . . . . . . . . . . . . . . . . . . . . . . . 10.1.3 Tracepoint Passcounts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.1.4 Tracepoint Action Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.1.5 Listing Tracepoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.1.6 Starting and Stopping Trace Experiments . . . . . . . . . . . . . 10.2 Using the Collected Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.2.1 tfind n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.2.2 tdump. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.2.3 save-tracepoints filename . . . . . . . . . . . . . . . . . . . . . . . . 10.3 Convenience Variables for Tracepoints . . . . . . . . . . . . . . . . . . . . . 11 Debugging Programs That Use Overlays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 11.1 11.2 11.3 11.4 12 107 107 108 108 109 110 110 111 111 113 114 114 How Overlays Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Overlay Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Automatic Overlay Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . Overlay Sample Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 116 118 119 Using gdb with Different Languages . . . . . 121 12.1 Switching Between Source Languages . . . . . . . . . . . . . . . . . . . . . . 12.1.1 List of Filename Extensions and Languages . . . . . . . . . . . . 12.1.2 Setting the Working Language . . . . . . . . . . . . . . . . . . . . . . . . 12.1.3 Having gdb Infer the Source Language . . . . . . . . . . . . . . . . 12.2 Displaying the Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.3 Type and Range Checking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.3.1 An Overview of Type Checking . . . . . . . . . . . . . . . . . . . . . . . 12.3.2 An Overview of Range Checking . . . . . . . . . . . . . . . . . . . . . . 12.4 Supported Languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.1 C and C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.1.1 C and C++ Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.1.2 C and C++ Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.1.3 C++ Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.1.4 C and C++ Defaults . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.1.5 C and C++ Type and Range Checks . . . . . . . . . . . . . . 12.4.1.6 gdb and C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.1.7 gdb Features for C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.1.8 Decimal Floating Point format . . . . . . . . . . . . . . . . . . . 12.4.2 Objective-C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 121 122 122 122 123 123 124 125 125 126 127 128 129 129 129 130 131 131 iv Debugging with gdb 12.4.2.1 Method Names in Commands . . . . . . . . . . . . . . . . . . . . 12.4.2.2 The Print Command With Objective-C . . . . . . . . . . . 12.4.3 Fortran . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.3.1 Fortran Operators and Expressions . . . . . . . . . . . . . . . 12.4.3.2 Fortran Defaults . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.3.3 Special Fortran Commands . . . . . . . . . . . . . . . . . . . . . . 12.4.4 Pascal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.5 Modula-2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.5.1 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.5.2 Built-in Functions and Procedures . . . . . . . . . . . . . . . . 12.4.5.3 Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.5.4 Modula-2 Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.5.5 Modula-2 Defaults . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.5.6 Deviations from Standard Modula-2 . . . . . . . . . . . . . . 12.4.5.7 Modula-2 Type and Range Checks . . . . . . . . . . . . . . . 12.4.5.8 The Scope Operators :: and . . . . . . . . . . . . . . . . . . . . 12.4.5.9 gdb and Modula-2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.6 Ada . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.6.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.6.2 Omissions from Ada . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.6.3 Additions to Ada . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.4.6.4 Stopping at the Very Beginning . . . . . . . . . . . . . . . . . . 12.4.6.5 Known Peculiarities of Ada Mode . . . . . . . . . . . . . . . . 12.5 Unsupported Languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 132 132 132 133 133 133 133 133 135 136 136 138 138 138 139 139 139 139 140 141 143 143 143 13 Examining the Symbol Table . . . . . . . . . . . . 145 14 Altering Execution . . . . . . . . . . . . . . . . . . . . . 151 14.1 14.2 14.3 14.4 14.5 14.6 15 Assignment to Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Continuing at a Different Address . . . . . . . . . . . . . . . . . . . . . . . . . Giving your Program a Signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Returning from a Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Calling Program Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Patching Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 152 153 153 154 154 gdb Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 15.1 Commands to Specify Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 15.2 Debugging Information in Separate Files . . . . . . . . . . . . . . . . . . . 163 15.3 Errors Reading Symbol Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166 16 Specifying a Debugging Target . . . . . . . . . . 169 16.1 Active Targets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 16.2 Commands for Managing Targets . . . . . . . . . . . . . . . . . . . . . . . . . . 170 16.3 Choosing Target Byte Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172 v 17 Debugging Remote Programs . . . . . . . . . . . 173 17.1 Connecting to a Remote Target . . . . . . . . . . . . . . . . . . . . . . . . . . . 17.2 Sending files to a remote system . . . . . . . . . . . . . . . . . . . . . . . . . . . 17.3 Using the gdbserver Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17.3.1 Running gdbserver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17.3.1.1 Attaching to a Running Program . . . . . . . . . . . . . . . . . 17.3.1.2 Multi-Process Mode for gdbserver . . . . . . . . . . . . . . . 17.3.1.3 Other Command-Line Arguments for gdbserver . . 17.3.2 Connecting to gdbserver . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17.3.3 Monitor Commands for gdbserver . . . . . . . . . . . . . . . . . . . . 17.4 Remote Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17.5 Implementing a Remote Stub . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17.5.1 What the Stub Can Do for You . . . . . . . . . . . . . . . . . . . . . . . 17.5.2 What You Must Do for the Stub . . . . . . . . . . . . . . . . . . . . . . 17.5.3 Putting it All Together. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 173 175 175 175 176 176 177 177 177 178 181 182 183 184 Configuration-Specific Information . . . . . . . 185 18.1 Native. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.1.1 HP-UX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.1.2 BSD libkvm Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.1.3 SVR4 Process Information . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.1.4 Features for Debugging djgpp Programs . . . . . . . . . . . . . . 18.1.5 Features for Debugging MS Windows PE Executables . . 18.1.5.1 Support for DLLs without Debugging Symbols . . . . 18.1.5.2 DLL Name Prefixes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.1.5.3 Working with Minimal Symbols . . . . . . . . . . . . . . . . . . 18.1.6 Commands Specific to gnu Hurd Systems . . . . . . . . . . . . . 18.1.7 QNX Neutrino . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.2 Embedded Operating Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.2.1 Using gdb with VxWorks . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.2.1.1 Connecting to VxWorks . . . . . . . . . . . . . . . . . . . . . . . . . 18.2.1.2 VxWorks Download . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.2.1.3 Running Tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.3 Embedded Processors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.3.1 ARM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.3.2 Renesas M32R/D and M32R/SDI . . . . . . . . . . . . . . . . . . . . . 18.3.3 M68k . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.3.4 MIPS Embedded . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.3.5 OpenRISC 1000 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.3.6 PowerPC Embedded . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.3.7 HP PA Embedded . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.3.8 Tsqware Sparclet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.3.8.1 Setting File to Debug . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.3.8.2 Connecting to Sparclet . . . . . . . . . . . . . . . . . . . . . . . . . . 18.3.8.3 Sparclet Download . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.3.8.4 Running and Debugging . . . . . . . . . . . . . . . . . . . . . . . . . 18.3.9 Fujitsu Sparclite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.3.10 Zilog Z8000 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 185 185 185 187 189 190 190 191 192 194 194 194 195 195 196 196 196 198 199 199 201 203 204 204 204 205 205 205 205 205 vi Debugging with gdb 18.3.11 Atmel AVR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.3.12 CRIS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.3.13 Renesas Super-H . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.4 Architectures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.4.1 x86 Architecture-specific Issues . . . . . . . . . . . . . . . . . . . . . . . 18.4.2 A29K . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.4.3 Alpha . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.4.4 MIPS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.4.5 HPPA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.4.6 Cell Broadband Engine SPU architecture . . . . . . . . . . . . . . 18.4.7 PowerPC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Controlling gdb . . . . . . . . . . . . . . . . . . . . . . . . 211 19.1 19.2 19.3 19.4 19.5 19.6 19.7 19.8 20 206 206 207 207 207 207 207 208 209 209 210 Prompt. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Command Editing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Command History. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Screen Size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Configuring the Current ABI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Optional Warnings and Messages . . . . . . . . . . . . . . . . . . . . . . . . . . Optional Messages about Internal Happenings . . . . . . . . . . . . . . 211 211 211 213 214 214 215 217 Canned Sequences of Commands . . . . . . . . 221 20.1 20.2 20.3 20.4 User-defined Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . User-defined Command Hooks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . Command Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Commands for Controlled Output . . . . . . . . . . . . . . . . . . . . . . . . . 221 222 223 224 21 Command Interpreters . . . . . . . . . . . . . . . . . . 227 22 gdb Text User Interface . . . . . . . . . . . . . . . . . 229 22.1 22.2 22.3 22.4 22.5 23 TUI Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . TUI Key Bindings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . TUI Single Key Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . TUI-specific Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . TUI Configuration Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229 230 231 231 233 Using gdb under gnu Emacs . . . . . . . . . . . . 235 vii 24 The gdb/mi Interface . . . . . . . . . . . . . . . . . . . 237 Function and Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Notation and Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.3 gdb/mi Command Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.3.1 gdb/mi Input Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.3.2 gdb/mi Output Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.4 gdb/mi Compatibility with CLI . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.5 gdb/mi Development and Front Ends . . . . . . . . . . . . . . . . . . . . . 24.6 gdb/mi Output Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.6.1 gdb/mi Result Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.6.2 gdb/mi Stream Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.6.3 gdb/mi Async Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.7 Simple Examples of gdb/mi Interaction. . . . . . . . . . . . . . . . . . . . 24.8 gdb/mi Command Description Format . . . . . . . . . . . . . . . . . . . . 24.9 gdb/mi Breakpoint Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.10 gdb/mi Program Context . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.11 gdb/mi Thread Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.12 gdb/mi Program Execution. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.13 gdb/mi Stack Manipulation Commands . . . . . . . . . . . . . . . . . . 24.14 gdb/mi Variable Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.15 gdb/mi Data Manipulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.16 gdb/mi Tracepoint Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.17 gdb/mi Symbol Query Commands . . . . . . . . . . . . . . . . . . . . . . . 24.18 gdb/mi File Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.19 gdb/mi Target Manipulation Commands . . . . . . . . . . . . . . . . . 24.20 gdb/mi File Transfer Commands . . . . . . . . . . . . . . . . . . . . . . . . . 24.21 Miscellaneous gdb/mi Commands . . . . . . . . . . . . . . . . . . . . . . . . 25 gdb Annotations . . . . . . . . . . . . . . . . . . . . . . . 293 25.1 25.2 25.3 25.4 25.5 25.6 25.7 26 237 237 237 237 238 240 240 240 240 241 241 242 243 244 251 254 255 261 265 271 277 277 280 283 287 288 What is an Annotation? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The Server Prefix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Annotation for gdb Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Invalidation Notices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Running the Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Displaying Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293 294 294 294 295 295 296 Reporting Bugs in gdb . . . . . . . . . . . . . . . . . . 297 26.1 Have You Found a Bug? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297 26.2 How to Report Bugs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297 viii Debugging with gdb 27 Command Line Editing . . . . . . . . . . . . . . . . . 301 27.1 Introduction to Line Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27.2 Readline Interaction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27.2.1 Readline Bare Essentials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27.2.2 Readline Movement Commands . . . . . . . . . . . . . . . . . . . . . . . 27.2.3 Readline Killing Commands . . . . . . . . . . . . . . . . . . . . . . . . . . 27.2.4 Readline Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27.2.5 Searching for Commands in the History . . . . . . . . . . . . . . . 27.3 Readline Init File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27.3.1 Readline Init File Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27.3.2 Conditional Init Constructs . . . . . . . . . . . . . . . . . . . . . . . . . . 27.3.3 Sample Init File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27.4 Bindable Readline Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27.4.1 Commands For Moving . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27.4.2 Commands For Manipulating The History . . . . . . . . . . . . . 27.4.3 Commands For Changing Text . . . . . . . . . . . . . . . . . . . . . . . 27.4.4 Killing And Yanking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27.4.5 Specifying Numeric Arguments . . . . . . . . . . . . . . . . . . . . . . . 27.4.6 Letting Readline Type For You . . . . . . . . . . . . . . . . . . . . . . . 27.4.7 Keyboard Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27.4.8 Some Miscellaneous Commands . . . . . . . . . . . . . . . . . . . . . . . 27.5 Readline vi Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 301 301 301 302 302 303 303 304 304 309 310 313 313 313 315 316 317 317 317 318 319 Using History Interactively . . . . . . . . . . . . . . 321 28.1 History Expansion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28.1.1 Event Designators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28.1.2 Word Designators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28.1.3 Modifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321 321 321 322 Appendix A Formatting Documentation . . . . 325 Appendix B Installing gdb . . . . . . . . . . . . . . . . 327 B.1 B.2 B.3 B.4 B.5 Requirements for Building gdb . . . . . . . . . . . . . . . . . . . . . . . . . . . . Invoking the gdb ‘configure’ Script . . . . . . . . . . . . . . . . . . . . . . . Compiling gdb in Another Directory . . . . . . . . . . . . . . . . . . . . . . . Specifying Names for Hosts and Targets . . . . . . . . . . . . . . . . . . . . ‘configure’ Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Appendix C 327 327 329 330 330 Maintenance Commands . . . . . . 333 ix Appendix D gdb Remote Serial Protocol . . . 339 D.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.2 Packets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.3 Stop Reply Packets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.4 General Query Packets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.5 Register Packet Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.6 Tracepoint Packets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.7 Host I/O Packets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.8 Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.9 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.10 File-I/O Remote Protocol Extension . . . . . . . . . . . . . . . . . . . . . . D.10.1 File-I/O Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.10.2 Protocol Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.10.3 The F Request Packet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.10.4 The F Reply Packet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.10.5 The ‘Ctrl-C’ Message . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.10.6 Console I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.10.7 List of Supported Calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . open . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . close . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . read . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . write . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . lseek . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . rename . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . unlink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . stat/fstat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . gettimeofday . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . isatty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.10.8 Protocol-specific Representation of Datatypes . . . . . . . . . Integral Datatypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Pointer Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Memory Transfer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . struct stat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . struct timeval . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.10.9 Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Open Flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . mode t Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Errno Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Lseek Flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Limits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.10.10 File-I/O Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.11 Library List Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D.12 Memory Map Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339 340 347 348 358 358 360 362 362 363 363 363 364 364 365 365 365 366 367 367 367 368 368 369 369 370 370 370 371 371 371 372 372 372 373 373 373 373 374 374 374 375 376 x Debugging with gdb Appendix E The GDB Agent Expression Mechanism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377 E.1 E.2 E.3 E.4 E.5 E.6 General Bytecode Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Bytecode Descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using Agent Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Varying Target Capabilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Tracing on Symmetrix. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Rationale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Appendix F 377 379 383 384 384 386 Target Descriptions . . . . . . . . . . . 389 F.1 Retrieving Descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . F.2 Target Description Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . F.2.1 Inclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . F.2.2 Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . F.2.3 Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . F.2.4 Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . F.2.5 Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . F.3 Predefined Target Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . F.4 Standard Target Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . F.4.1 ARM Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . F.4.2 MIPS Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . F.4.3 M68K Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . F.4.4 PowerPC Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389 390 390 390 391 391 391 392 393 393 393 394 394 Appendix G GNU GENERAL PUBLIC LICENSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395 Preamble . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION . . . . . . . . . . . . . . . . . . . 396 How to Apply These Terms to Your New Programs . . . . . . . . . . . . . . . 400 Appendix H GNU Free Documentation License . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401 H.1 ADDENDUM: How to use this License for your documents . . 407 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 409 1 Summary of gdb The purpose of a debugger such as gdb is to allow you to see what is going on “inside” another program while it executes—or what another program was doing at the moment it crashed. gdb can do four main kinds of things (plus other things in support of these) to help you catch bugs in the act: • Start your program, specifying anything that might affect its behavior. • Make your program stop on specified conditions. • Examine what has happened, when your program has stopped. • Change things in your program, so you can experiment with correcting the effects of one bug and go on to learn about another. You can use gdb to debug programs written in C and C++. For more information, see Section 12.4 [Supported Languages], page 125. For more information, see Section 12.4.1 [C and C++], page 125. Support for Modula-2 is partial. [Modula-2], page 133. For information on Modula-2, see Section 12.4.5 Debugging Pascal programs which use sets, subranges, file variables, or nested functions does not currently work. gdb does not support entering expressions, printing values, or similar features using Pascal syntax. gdb can be used to debug programs written in Fortran, although it may be necessary to refer to some variables with a trailing underscore. gdb can be used to debug programs written in Objective-C, using either the Ap- ple/NeXT or the GNU Objective-C runtime. Free Software gdb is free software, protected by the gnu General Public License (GPL). The GPL gives you the freedom to copy or adapt a licensed program—but every person getting a copy also gets with it the freedom to modify that copy (which means that they must get access to the source code), and the freedom to distribute further copies. Typical software companies use copyrights to limit your freedoms; the Free Software Foundation uses the GPL to preserve these freedoms. Fundamentally, the General Public License is a license which says that you have these freedoms and that you cannot take these freedoms away from anyone else. Free Software Needs Free Documentation The biggest deficiency in the free software community today is not in the software—it is the lack of good free documentation that we can include with the free software. Many of our most important programs do not come with free reference manuals and free introductory texts. Documentation is an essential part of any software package; when an important free software package does not come with a free manual and a free tutorial, that is a major gap. We have many such gaps today. 2 Debugging with gdb Consider Perl, for instance. The tutorial manuals that people normally use are non-free. How did this come about? Because the authors of those manuals published them with restrictive terms—no copying, no modification, source files not available—which exclude them from the free software world. That wasn’t the first time this sort of thing happened, and it was far from the last. Many times we have heard a GNU user eagerly describe a manual that he is writing, his intended contribution to the community, only to learn that he had ruined everything by signing a publication contract to make it non-free. Free documentation, like free software, is a matter of freedom, not price. The problem with the non-free manual is not that publishers charge a price for printed copies—that in itself is fine. (The Free Software Foundation sells printed copies of manuals, too.) The problem is the restrictions on the use of the manual. Free manuals are available in source code form, and give you permission to copy and modify. Non-free manuals do not allow this. The criteria of freedom for a free manual are roughly the same as for free software. Redistribution (including the normal kinds of commercial redistribution) must be permitted, so that the manual can accompany every copy of the program, both on-line and on paper. Permission for modification of the technical content is crucial too. When people mod- ify the software, adding or changing features, if they are conscientious they will change the manual too—so they can provide accurate and clear documentation for the modified program. A manual that leaves you no choice but to write a new manual to document a changed version of the program is not really available to our community. Some kinds of limits on the way modification is handled are acceptable. For example, requirements to preserve the original author’s copyright notice, the distribution terms, or the list of authors, are ok. It is also no problem to require modified versions to include notice that they were modified. Even entire sections that may not be deleted or changed are acceptable, as long as they deal with nontechnical topics (like this one). These kinds of restrictions are acceptable because they don’t obstruct the community’s normal use of the manual. However, it must be possible to modify all the technical content of the manual, and then distribute the result in all the usual media, through all the usual channels. Otherwise, the restrictions obstruct the use of the manual, it is not free, and we need another manual to replace it. Please spread the word about this issue. Our community continues to lose manuals to proprietary publishing. If we spread the word that free software needs free reference manuals and free tutorials, perhaps the next person who wants to contribute by writing documentation will realize, before it is too late, that only free manuals contribute to the free software community. If you are writing documentation, please insist on publishing it under the GNU Free Documentation License or another free documentation license. Remember that this deci- sion requires your approval—you don’t have to let the publisher decide. Some commercial publishers will use a free license if you insist, but they will not propose the option; it is up to you to raise the issue and say firmly that this is what you want. If the publisher you are dealing with refuses, please try other publishers. If you’re not sure whether a proposed license is free, write to licensing@gnu.org. 3 You can encourage commercial publishers to sell more free, copylefted manuals and tutorials by buying them, and particularly by buying copies from the publishers that paid for their writing or for major improvements. Meanwhile, try to avoid buying non-free documentation at all. Check the distribution terms of a manual before you buy it, and insist that whoever seeks your business must respect your freedom. Check the history of the book, and try to reward the publishers that have paid or pay the authors to work on it. The Free Software Foundation maintains a list of free documentation published by other publishers, at http://www.fsf.org/doc/other-free-books.html. Contributors to gdb Richard Stallman was the original author of gdb, and of many other gnu programs. Many others have contributed to its development. This section attempts to credit major contrib- utors. One of the virtues of free software is that everyone is free to contribute to it; with regret, we cannot actually acknowledge everyone here. The file ‘ChangeLog’ in the gdb distribution approximates a blow-by-blow account. Changes much prior to version 2.0 are lost in the mists of time. Plea: Additions to this section are particularly welcome. If you or your friends (or enemies, to be evenhanded) have been unfairly omitted from this list, we would like to add your names! So that they may not regard their many labors as thankless, we particularly thank those who shepherded gdb through major releases: Andrew Cagney (releases 6.3, 6.2, 6.1, 6.0, 5.3, 5.2, 5.1 and 5.0); Jim Blandy (release 4.18); Jason Molenda (release 4.17); Stan Shebs (release 4.14); Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9); Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4); John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9); Jim Kingdon (releases 3.5, 3.4, and 3.3); and Randy Smith (releases 3.2, 3.1, and 3.0). Richard Stallman, assisted at various times by Peter TerMaat, Chris Hanson, and Richard Mlynarik, handled releases through 2.8. Michael Tiemann is the author of most of the gnu C++ support in gdb, with significant additional contributions from Per Bothner and Daniel Berlin. James Clark wrote the gnu C++ demangler. Early work on C++ was by Peter TerMaat (who also did much general update work leading to release 3.0). gdb uses the BFD subroutine library to examine multiple object-file formats; BFD was a joint project of David V. Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore. David Johnson wrote the original COFF support; Pace Willison did the original support for encapsulated COFF. Brent Benson of Harris Computer Systems contributed DWARF 2 support. Adam de Boor and Bradley Davis contributed the ISI Optimum V support. Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS support. Jean-Daniel Fekete contributed Sun 386i support. Chris Hanson improved the HP9000 support. Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support. David Johnson con- tributed Encore Umax support. Jyrki Kuoppala contributed Altos 3068 support. Jeff Law contributed HP PA and SOM support. Keith Packard contributed NS32K support. 4 Debugging with gdb Doug Rabson contributed Acorn Risc Machine support. Bob Rusk contributed Harris Nighthawk CX-UX support. Chris Smith contributed Convex support (and Fortran de- bugging). Jonathan Stone contributed Pyramid support. Michael Tiemann contributed SPARC support. Tim Tucker contributed support for the Gould NP1 and Gould Powern- ode. Pace Willison contributed Intel 386 support. Jay Vosburgh contributed Symmetry support. Marko Mlinar contributed OpenRISC 1000 support. Andreas Schwab contributed M68K gnu/Linux support. Rich Schaefer and Peter Schauer helped with support of SunOS shared libraries. Jay Fenlason and Roland McGrath ensured that gdb and GAS agree about several machine instruction sets. Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM contributed remote debugging modules for the i960, VxWorks, A29K UDI, and RDI targets, respectively. Brian Fox is the author of the readline libraries providing command-line editing and command history. Andrew Beers of SUNY Buffalo wrote the language-switching code, the Modula-2 sup- port, and contributed the Languages chapter of this manual. Fred Fish wrote most of the support for Unix System Vr4. He also enhanced the command-completion support to cover C++ overloaded symbols. Hitachi America (now Renesas America), Ltd. H8/500, and Super-H processors. sponsored the support for H8/300, NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors. Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and M32R/D proces- sors. Toshiba sponsored the support for the TX39 Mips processor. Matsushita sponsored the support for the MN10200 and MN10300 processors. Fujitsu sponsored the support for SPARClite and FR30 processors. Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware watchpoints. Michael Snyder added support for tracepoints. Stu Grossman wrote gdbserver. Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made nearly innumerable bug fixes and cleanups throughout gdb. The following people at the Hewlett-Packard Company contributed support for the PA- RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0 (narrow mode), HP’s implementation of kernel threads, HP’s aC++ compiler, and the Text User Interface (nee Terminal User Interface): Ben Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann, Satish Pai, India Paul, Steve Rehrauer, and Elena Zannoni. Kim Haase provided HP-specific information in this manual. DJ Delorie ported gdb to MS-DOS, for the DJGPP project. Robert Hoehne made significant contributions to the DJGPP port. Cygnus Solutions has sponsored gdb maintenance and much of its development since 1991. Cygnus engineers who have worked on gdb fulltime include Mark Alexander, Jim 5 Blandy, Per Bothner, Kevin Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler, Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton, JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner, Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David Zuhn have made contributions both large and small. Andrew Cagney, Fernando Nasser, and Elena Zannoni, while working for Cygnus Solu- tions, implemented the original gdb/mi interface. Jim Blandy added support for preprocessor macros, while working for Red Hat. Andrew Cagney designed gdb’s architecture vector. Many people including Andrew Cagney, Stephane Carrez, Randolph Chung, Nick Duffek, Richard Henderson, Mark Ket- tenis, Grace Sainsbury, Kei Sakamoto, Yoshinori Sato, Michael Snyder, Andreas Schwab, Jason Thorpe, Corinna Vinschen, Ulrich Weigand, and Elena Zannoni, helped with the migration of old architectures to this new framework. Andrew Cagney completely re-designed and re-implemented gdb’s unwinder framework, this consisting of a fresh new design featuring frame IDs, independent frame sniffers, and the sentinel frame. Mark Kettenis implemented the dwarf 2 unwinder, Jeff Johnston the libunwind unwinder, and Andrew Cagney the dummy, sentinel, tramp, and trad unwinders. The architecture-specific changes, each involving a complete rewrite of the architecture’s frame code, were carried out by Jim Blandy, Joel Brobecker, Kevin Buettner, Andrew Cagney, Stephane Carrez, Randolph Chung, Orjan Friberg, Richard Henderson, Daniel Jacobowitz, Jeff Johnston, Mark Kettenis, Theodore A. Roth, Kei Sakamoto, Yoshinori Sato, Michael Snyder, Corinna Vinschen, and Ulrich Weigand. Christian Zankel, Ross Morley, Bob Wilson, and Maxim Grigoriev from Tensilica, Inc. contributed support for Xtensa processors. Others who have worked on the Xtensa port of gdb in the past include Steve Tjiang, John Newlin, and Scott Foehner.

28,408

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧