Paste and fetch code snippets

To paste snippets of code or whole files to a server or fetch them from the server, use one of the following code pasting services:

  • DPaste.com
  • Pastebin.com

For example, you might ask colleagues to review a change that you plan to submit to a version control system. If you use the Git version control system, create a diff view by going to Tools > Git > Local Repository > Diff. Then, upload its contents to the server by going to Tools > Code Pasting > Paste Snippet.

The reviewers can retrieve the code snippet by selecting Tools > Code Pasting > Fetch Snippet. If they have the project currently opened in Qt Creator, they can apply and test the change by going to Tools > Git > Local Repository > Patch > Apply from Editor.

Paste snippets

To paste a snippet of code onto the server:

  1. Go to Tools > Code Pasting > Paste Snippet or press Alt+C,Alt+P.

    {Send to Codepaster dialog}

  2. In Protocol, select the code pasting service to use.
  3. In Expires after, specify the time to keep the pasted snippet on the server.
  4. In Username and Description, enter your username and add information about the pasted content.
  5. Check and edit the content to paste.
  6. Select Paste.

By default, Qt Creator copies the URL of the snippet to the clipboard and displays the URL in General Messages.

To paste a diff, right-click a chunk and select Send Chunk to CodePaster in the context menu.

Fetch snippets

To fetch a snippet of code from the server:

  1. Go to Tools > Code Pasting > Fetch Snippet or press Alt+C,Alt+F.
  2. Select the snippet to fetch from the list.

To fetch the content stored at a URL, select Tools > Code Pasting > Fetch from URL.

Set code pasting preferences

To set preferences for a code pasting service:

  1. Go to Preferences > Code Pasting > General.

    {Code Pasting preferences}

  2. In Default protocol, select a code pasting service to use by default.
  3. In Username, enter your username.
  4. In Expires after, specify the time to keep the pasted snippet on the server.
  5. Select Copy-paste URL to clipboard to copy the URL of the post on the code pasting service to the clipboard when you paste a post.
  6. Select Display General Messages after sending a post to display the URL in General Messages when you paste a post.

Set a shared network drive for code pasting

Go to Preferences > Code Pasting > Fileshare to specify the path to a shared network drive.

The code snippets are copied to the drive as simple files. You have to delete obsolete files from the drive manually.

See also Compare files and Git.

Copyright © The Qt Company Ltd. and other contributors. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.