Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Qt 在等离子体中连接小部件的信号_Qt_Plasmoid - Fatal编程技术网

Qt 在等离子体中连接小部件的信号

Qt 在等离子体中连接小部件的信号,qt,plasmoid,Qt,Plasmoid,我是Qt的新手,在写等离子体的时候,我正试图用一个按钮和一个函数来连接被触发的信号。我正在尝试使用一个外部函数作为Plasma::Buttown类型对象的公共函数,以便使用它将其与单击的信号连接起来?有了gtk,它就像在上一样简单…\u单击“执行此操作”,但在qt中是否有一种简单的方法,可以消除使用插槽的需要 #include "plasma-tutorial1.h" #include<string.h> #include <stdlib.h> #include <

我是Qt的新手,在写等离子体的时候,我正试图用一个按钮和一个函数来连接被触发的信号。我正在尝试使用一个外部函数作为Plasma::Buttown类型对象的公共函数,以便使用它将其与单击的信号连接起来?有了gtk,它就像在上一样简单…\u单击“执行此操作”,但在qt中是否有一种简单的方法,可以消除使用插槽的需要

#include "plasma-tutorial1.h"
#include<string.h>
#include <stdlib.h>
#include <QGraphicsLinearLayout>
#include <QPainter>
#include <QFontMetrics>
#include <QSizeF>
#include <QTextEdit>
#include <plasma/svg.h>
#include <plasma/theme.h>
#include <plasma/widgets/lineedit.h>
#include <plasma/widgets/pushbutton.h>
#include <plasma/widgets/textedit.h> 
//PlasmaTutorial1 mainf;

themainfunction(int choice,Plasma::LineEdit *m_lineEdit,
Plasma::TextEdit *m_displaytext)
{
char buffer[100];
const char *inp=(const char *)malloc(sizeof(char)*100);
QString input;
input=m_lineEdit->text();
QByteArray byteArray = input.toUtf8();
inp = byteArray.constData();
char *expression;
expression=(char *)malloc(sizeof(char)*100);
strcpy(expression,"sudo apt-");

switch(choice)
{
case 1:{
        strcat(expression,"get install ");
        strcat(expression,inp);
        break;
      };
case 2:{
        strcat(expression,"get remove ");
        strcat(expression,inp);
        break;
      };
case 3:{
        strcat(expression,"cache search ");
        strcat(expression,inp);
        break;
      };
};
/*
FILE* in;
FILE* ptr=fopen("new.txt","w");
FILE *popen();
if(!(in = popen("cal","r")))
    {return;}

    while(fgets(buffer, 100, in) != NULL) {
*/
m_displaytext->append("yeah!");
//    fprintf(ptr,"%s",buffer);

            //}
//pclose(in);
//fclose(ptr);
}
PlasmaTutorial1::PlasmaTutorial1(QObject *parent, const QVariantList &args)
    : Plasma::Applet(parent, args),
    m_svg(this),
    m_icon("document")
{
    m_svg.setImagePath("widgets/background");
    // this will get us the standard applet background, for free!
    setBackgroundHints(DefaultBackground);
    resize(200, 200);
}


PlasmaTutorial1::~PlasmaTutorial1()
{
    if (hasFailedToLaunch()) {
        // Do some cleanup here
    } else {
        // Save settings
    }
}

void PlasmaTutorial1::init()
{

  /*  // A small demonstration of the setFailedToLaunch function
    if (m_icon.isNull()) {
        setFailedToLaunch(true, "No world to say hello");
    }*/
Counter rt;
    QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(this);
  layout->setOrientation(Qt::Vertical); //so widgets will be stacked up/down

  m_lineEdit = new Plasma::LineEdit(this);
  m_lineEdit->setText("Enter the package name here");

  m_displaytext = new Plasma::TextEdit(this);
  m_displaytext->setText("Terminal");

  m_installButton = new Plasma::PushButton(this);
  m_installButton->setText("Install");
  connect(m_installButton, SIGNAL(clicked()),&rt,SLOT(themainfunction(1,m_lineEdit,m_displaytext)));

  m_removeButton = new Plasma::PushButton(this);
  m_removeButton->setText("Remove");
  // m_removeButton->clicked()

  connect(m_removeButton, SIGNAL(clicked()),&rt,SLOT(themainfunction(2,m_lineEdit,m_displaytext)));

  m_searchButton = new Plasma::PushButton(this);
  m_searchButton->setText("Search");
  connect(m_searchButton, SIGNAL(clicked()),&rt,SLOT(themainfunction(3,m_lineEdit,m_displaytext)));


  layout->addItem(m_lineEdit);
  layout->addItem(m_installButton);
  layout->addItem(m_removeButton);
  layout->addItem(m_searchButton);
  layout->addItem(m_displaytext);   
  m_displaytext->append("yo baby!");    
} 

/* 
void PlasmaTutorial1::paintInterface(QPainter *p,
        const QStyleOptionGraphicsItem *option, const QRect &contentsRect)
{
    p->setRenderHint(QPainter::SmoothPixmapTransform);
    p->setRenderHint(QPainter::Antialiasing);

    // Now we draw the applet, starting with our svg
    m_svg.resize((int)contentsRect.width(), (int)contentsRect.height());
    m_svg.paint(p, (int)contentsRect.left(), (int)contentsRect.top());

    // We place the icon and text
    p->drawPixmap(7, 0, m_icon.pixmap((int)contentsRect.width(),(int)contentsRect.width()-14));
    p->save();
    p->setPen(Qt::white);
    p->drawText(contentsRect,
                Qt::AlignBottom | Qt::AlignHCenter,
                "Hello Plasmoid!");
    p->restore();
}
 */
// This is the command that links your applet to the .desktop file
K_EXPORT_PLASMA_APPLET(tutorial1, PlasmaTutorial1)

#include "plasma-tutorial1.moc"
#包括“plasma-tutorial1.h”
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
//等离子管;
主功能(int选项,Plasma::LineEdit*m_LineEdit,
Plasma::text编辑*m_显示文本)
{
字符缓冲区[100];
常量字符*inp=(常量字符*)malloc(sizeof(字符)*100);
QString输入;
输入=m_lineEdit->text();
QByteArray byteArray=input.toUtf8();
inp=byteArray.constData();
字符*表达式;
表达式=(char*)malloc(sizeof(char)*100);
strcpy(表示“sudo apt-”);
开关(选择)
{
案例1:{
strcat(表达式“get-install”);
strcat(表达式,inp);
打破
};
案例2:{
strcat(表达式“get-remove”);
strcat(表达式,inp);
打破
};
案例3:{
strcat(表达式,“缓存搜索”);
strcat(表达式,inp);
打破
};
};
/*
文件*in;
文件*ptr=fopen(“new.txt”,“w”);
文件*popen();
如果(!(in=popen(“cal”,“r”))
{return;}
while(fgets(缓冲区,100英寸)!=NULL){
*/
m_displaytext->append(“耶!”);
//fprintf(ptr,“%s”,缓冲区);
//}
//pclose(in);
//fclose(ptr);
}
PlasmaTutorial1::PlasmaTutorial1(QObject*父对象、常量QVariantList和参数)
:Plasma::小程序(父级,参数),
m_svg(这个),
m_图标(“文档”)
{
m_svg.setImagePath(“小部件/背景”);
//这将使我们免费获得标准的小程序背景!
挫折背景提示(默认背景);
调整大小(200200);
}
PlasmaTutorial1::~PlasmaTutorial1()
{
如果(hasfailedtolunch()){
//在这里做些清理
}否则{
//保存设置
}
}
void PlasmaTutorial1::init()
{
/*//setFailedToRunch函数的一个小演示
if(m_icon.isNull()){
setFailedToLaunch(真的,“没有世界可以打招呼”);
}*/
计数器rt;
QGraphicsLinearLayout*layout=新的QGraphicsLinearLayout(此);
布局->设置方向(Qt::垂直);//因此小部件将向上/向下堆叠
m_lineEdit=新等离子体::lineEdit(此);
m_lineEdit->setText(“在此处输入包名”);
m_displaytext=新血浆::文本编辑(此);
m_displaytext->setText(“终端”);
m_installButton=新等离子::按钮(本);
m_installButton->setText(“安装”);
连接(m_安装按钮、信号(单击())、&rt、插槽(主功能(1、m_lineEdit、m_displaytext));
m_removeButton=新等离子::按钮(本);
m_removeButton->setText(“移除”);
//m_removeButton->单击()
连接(m_removeButton,SIGNAL(clicked()),&rt,SLOT(主功能(2,m_lineEdit,m_displaytext)));
m_searchButton=新等离子::按钮(本);
m_searchButton->setText(“搜索”);
连接(m_searchButton,SIGNAL(clicked()),&rt,插槽(主功能(3,m_lineEdit,m_displaytext)));
布局->添加项(m_lineEdit);
布局->添加项(m_安装按钮);
布局->添加项(m_removeButton);
布局->添加项(m_搜索按钮);
布局->添加项(m_displaytext);
m_displaytext->append(“哟宝贝!”);
} 
/* 
void PlasmatAutorial1::paintInterface(QPainter*p,
常量QSTYLEOPTIONGRAPHIC SITEM*选项、常量QRect和内容RECT)
{
p->SetRenderInt(QPaint::SmoothPixmapTransform);
p->SetRenderInt(QPaint::抗锯齿);
//现在我们从svg开始绘制小程序
m_svg.resize((int)contentsRect.width(),(int)contentsRect.height());
m_svg.paint(p,(int)contentsRect.left(),(int)contentsRect.top());
//我们放置图标和文本
p->drawPixmap(7,0,m_图标.pixmap((int)contentsRect.width(),(int)contentsRect.width()-14));
p->save();
p->setPen(Qt::白色);
p->drawText(内容引用,
Qt::AlignBottom | Qt::AlignHCenter,
“你好,等离子体!”);
p->restore();
}
*/
//这是将小程序链接到.desktop文件的命令
K_导出_PLASMA_小程序(教程1,PlasmatAutorial1)
#包括“plasma-tutorial1.moc”

假设我想在单击安装按钮的信号时连接主函数()。我该怎么做?我怎样才能在plasma中导出一个类呢?

我知道我遗漏了什么。我们不能在插槽函数中将对象作为参数传递。现在它运行平稳。谢谢你的回复。

提供一些代码,并对这个问题更具体一点,怎么样?此外,阅读一点文档可能会有所帮助:当您拥有能够安全完成所有操作的qstring时,停止执行这些C风格的字符串操作——这是在浪费时间&可能会在代码中引入bug。至于插槽,它们不是那样工作的。阅读kfunk指出的文档-你不能像那样传递参数,插槽也不能是自由函数。我如何从plasma中的Putton派生类。我试过了,但遇到了很多错误。你能给我一个方法来做这件事,这样我就可以使用插槽功能吗?它说,在运行时,没有这样的插槽找到。