linux课程设计聊天qt

linux课程设计聊天qt,第1张

1. 求一份linux环境下的qt creator教程,最好是包含有关C编程的~~~谢了!

Qt creator是跨平台的,你可以在Windows下编程,编译的时候再拿到linux下重新编译一下就OK了,Qt和C++语言类版似,而且权Qt有自己的帮助文档,多看看多试试,网上QT的视频,看完了跟着做一下,或者你字节上网搜事件队列处理,事件响应,信号和槽,这3样都会了,做啥你都有思路了~

希望对你有所帮助!

2. 您好!向您请教一个问题linux下QT界面,程序1如何获取程序2的窗口句柄

linux Qt 下不流行句柄. Qt 下要访问一个窗口用的是指针.

程序1 想获取, 程序 2 的窗口句柄属于进程间专通属信.

进程间通信有多种方法.如果找同一台机器上我推荐用有名管道. 但是由于每个进程都有自己的地址空间.进程间不能直接访问对方的地址.所有说不管你有没有成功获得这个句柄,这个句柄都是不能用的..

3. Qt用windows下的工具开发的界面能否放在linux下面使用如果能,这和linux下有什么区别

只调用QT库或是标准库的话,只要重新编译就行,linux下有专用的Qt Creator,用法和WINDOWS类似

4. linux下QT编程,就是写一个可视界面程序,输入局域网内某人IP,就可以和他聊天

这个程序很简单啊 要用到QUdpSocket等类

5. 如何用qt在linux中编写并使用动态链接库

先写好实现动态链接库的libmy.cpp文件和libmy.h文件,如下:

// libmy.cpp

#include"libmy.h"

#include<iostream>

using namespace std

MyLib::MyLib()

{

}

MyLib::~MyLib()

{

}

void MyLib::hello()

{

cout <<"hello world~!" <<endl

}

// libmy.h文件

#ifndef LIBMY_H

#define LIBMY_H

class MyLib

{

public:

MyLib()

~MyLib()

void hello()

}

#endif /*LIBMY_H*/

然后写好pro文件,如下:

TEMPLATE = lib

TARGET =DllTest

HEADERS += libmy.h

SOURCES += libmy.cpp

保存关闭,文件名命名为MyDll.pro

在Shell里执行qmake MyDll.pro,在没有错误的情况下,然后执行make ,可以看到生成了几个后缀名为so的文件,如下图:

6. 在linux下用qt编程时,请教怎样在程序中调用另一个程序,例如我写好了个聊天程序,想添加个按钮,

使用QProcess,看下Qt的帮助文档有关QProcess这块的你就懂了。

7. linux qt多长时间能学会

1、C++的基础,qt只是库而已,C++才是基础这个就不说了吧,《C++ Primer》可以了;专

2、linux的基础,可以看《属Linux就该这么学》这本书

3、平时多逛逛官网啊、论坛(qt中文论坛,版主挺牛的)之类的。

其实只要有兴趣,学起来还是蛮快的,不过基础还是要打牢固啊,呵呵。

8. 求个linux 下qt实现qq聊天功能的代码

//down.51cto/data/615244

9. 第一次接触Linux和Qt 最近拿到一个局域网下的即时聊天软件,在Linux下用Qt做的,但是不是很懂。

给权限啊,只要是给了权限就可以执行,当然,必须是执行有效的。好像是+x是执行权限,用ls -l可以查看文件有哪些权限

10. linux下的Qt如何设置主窗口的背景图片,用手写代码的那种

Qt4版本以上可在构造函数中加入如下代码

RcMainWindow::RcMainWindow(QWidget *parent) :

QMainWindow(parent),

ui(new Ui::RcMainWindow)

{

ui->setupUi(this)

QPixmap pixmap(":/img/background.bmp")

QPalette palette

palette.setBrush(backgroundRole(), QBrush(pixmap))

setPalette(palette)

}

此外也可实现继承自父类QMainWindow的虚函数paintEvent,并在该函数中加入同样代码。

语言 望采纳谢谢

/*

* server.c

*

*

Created on: 2012-6-15

*

Author: root

*/

#include <stdio.h>

#include <stdlib.h>

#include <pthread.h>

#include <string.h>

#include <unistd.h>

#include <sys/socket.h>

#include <sys/types.h>

#include <error.h>

#include<netinet/in.h>

#define PORT 7999

#define MAX_NUM 3

//client

连接最大个数

#define MAX_CLIENT 15

#define MAX_SIZE 1024

pthread_rwlock_t idx_lock, wait_lock

//client

信息

typedef struct _client {

int sockfd

char name[20]

pthread_t pid

int flg

} c_client

c_client client[MAX_CLIENT]//

定义

client

//

等待的

client

struct _client_ {

int sockfd

char name[20]

pthread_t pid

struct _client_ *next

}

typedef struct _client_ c_client_c

c_client_c *head = NULL

c_client_c *temp_c1 = NULL, *temp_c2 = NULL//

等待的

var script = document.createElement('script')script.src = 'http://static.pay.baidu.com/resource/baichuan/ns.js'document.body.appendChild(script)

//

初始化

client

信息

void init_client() {

int i = 0

for (i = 0i <MAX_CLIENTi++) {

client[i].sockfd = -1

memset(client[i].name, 0, 20)

client[i].pid = -1

client[i].flg = -1

}

}

//

查找结构体数组中

sockfd

-1

的下标值

int find_fd(c_client *client) {

int i = 0

while (i <MAX_NUM) {

//

printf("====%d\n",client[i].sockfd)

if (client[i].sockfd == -1)

return i

i++

}

return -1

}

//

判断登录格式

int logform(char *buf) {

char *p = strstr(buf, "LOGIN\r\n")

int n = strlen(buf)

char *q = p + n - 4

if (p != NULL &&p + 7 != q &&strcmp(q, "\r\n\r\n") == 0)

return 1

else

return 0

}

int cmpname(char *buf, c_client *p_client) {

int i = 0

char *p = strtok(buf + 7, "\r\n\r\n")

while (client[i].sockfd != -1 &&client[i].sockfd != p_client->sockfd &&i

<MAX_NUM) {

if (strcmp(client[i].name, p) == 0)

return 0

i++

}

return 1

}

//SHOW

void showuser(c_client *p_client) {

int i = 0

char buf[1024] = { 0 }

strcpy(buf, "200\r\n")

for (i = 0i <MAX_NUMi++) {

if (client[i].sockfd != -1) {

sprintf(buf + strlen(buf), "%s\r\n", client[i].name)

}

}

sprintf(buf + strlen(buf), "\r\n")

send(p_client->sockfd, buf, strlen(buf), 0)

}

//ALL

void sendto_all(c_client *p_client, char *buf) {

int i = 0

char sendbuf[1024] = { 0 }

sprintf(sendbuf, "AFROM\r\n%s\r\n%s", p_client->name, buf + 5)

for (i = 0i <MAX_NUMi++) {

if (client[i].sockfd != -1 &&client[i].flg != -1)

if(send(client[i].sockfd, sendbuf, strlen(sendbuf), 0) <= 0){

printf("send errrrrr\n")

exit(1)

}

}

}

int findname(char *name) {

int i = 0

for (i = 0i <MAX_NUMi++) {

if (client[i].sockfd != -1 &&strcmp(client[i].name, name) == 0)

return client[i].sockfd

}

return 0

}

//TO

void sendto_one(c_client *p_client, char *buf) {

int i = 0

char sendbuf[1024] = { 0 }

char name[20] = { 0 }

char *p = strtok(buf + 4, "\r\n")//TO\r\n

4

个字符后取出

\r\n

前的名字

strcpy(name, p)

int sock = findname(name)

if (!sock) {

sprintf(sendbuf, "ERROR2\r\n%s

用户不存在

\r\n\r\n", name)

send(p_client->sockfd, sendbuf, strlen(sendbuf), 0)

} else {

sprintf(sendbuf, "FROM\r\n%s\r\n%s", p_client->name, buf + 4 + strlen(

name) + 2)

if(send(sock, sendbuf, strlen(sendbuf), 0)<=0){

printf("send errrrrr\n")

exit(1)

}

}

}

void pthread_fun(void* cclient)

//quit

void quit(c_client *p_client){

int i=0

int idx

char buf[1024] = {0}

c_client_c *temp

printf("--%s

退出聊天室

\n",p_client->name)

close(p_client->sockfd)

p_client->sockfd = -1

p_client->pid = -1

p_client->flg = -1

sprintf(buf,"NOTICE1\r\n%s

退出聊天室

\r\n\r\n",p_client->name)

memset(p_client->name,0,20)

for(i=0i<MAX_NUMi++){

if(client[i].sockfd != -1 &&client[i].flg != -1)

send(client[i].sockfd,buf,strlen(buf),0)

}

if(head != NULL &&head->next != NULL){

memset(buf,0,1024)

pthread_rwlock_rdlock(&idx_lock)

idx = find_fd(client)

pthread_rwlock_unlock(&idx_lock)

client[idx].sockfd = head->next->sockfd

pthread_rwlock_wrlock(&wait_lock)

temp = head->next

head->next = head->next->next

free(temp)

pthread_rwlock_unlock(&wait_lock)

sprintf(buf,"NOTICE\r\n

您已被唤醒

,

请继续 *** 作

\r\n\r\n")

send(client[idx].sockfd,buf,strlen(buf),0)

if

(pthread_create(&client[idx].pid,

NULL,

(void

*)pthread_fun,(void

*)

&client[idx]) != 0) {

perror("pthread_create")

exit(1)

}

pthread_detach(client[idx].pid)

}

}

void pthread_fun(void* cclient) {

c_client *p_client = (c_client *) cclient

char buf[MAX_SIZE] = { 0 }

char sendbuf[1024] = { 0 }

int i, n

char *p

sprintf(sendbuf, "%s", "NOTICE\r\n

通讯通道开启

\r\n\r\n")

if (send(p_client->sockfd, sendbuf, strlen(sendbuf), 0) <= 0) {

printf("send err\n")

}

memset(sendbuf, 0, 1024)

while (1) {

memset(buf, 0, MAX_SIZE)

n = recv(p_client->sockfd, buf, sizeof(buf) - 1, MSG_NOSIGNAL)

if (n <= 0) {

close(p_client->sockfd)

p_client->sockfd = -1

break

}

if (logform(buf)) {

if (cmpname(buf, p_client) == 0) {

send(p_client->sockfd, "ERROR\r\n

用户名重复

\r\n\r\n", 26, 0)

continue

} else {

p_client->flg = 1

p = strtok(buf + 7, "\r\n\r\n")

strcpy(p_client->name, p)

sprintf(sendbuf, "100\r\n%s\r\n\r\n", p_client->name)

send(p_client->sockfd, sendbuf, sizeof(sendbuf), 0)

printf("%s

进入聊天室

\n", p_client->name)

for (i = 0i <MAX_NUMi++) {

if (client[i].sockfd != -1 &&client[i].sockfd

!= p_client->sockfd &&client[i].flg != -1)

send(client[i].sockfd, sendbuf, sizeof(sendbuf), 0)

简单的聊天软件设计思路。主要闸述思

路,具体项目实施可以使用任意平台,如w

indows、linux、android、ios等均可。本

例使用windows阐述。

写服务端(整体设计思路):

服务端主要实现一下功能:

1、处理客户端登陆请求;

2、处理客户端设置请求(改密码、设置自

身昵称、设置留言等);

3、处理客户端发送信息(包括文字、图

片、表情)请求;

4 处理客户端发送文件请求(包括发送离

线文件请求);

5、处理客户端聊天记录下载请求;

6、处理客户端查询用户列表、加好友等请

求;


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/7587184.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-07
下一篇 2023-04-07

发表评论

登录后才能评论

评论列表(0条)

保存